locked
cant start-process with -credential RRS feed

  • Question

  • Hi, i have two 2012r2 servers, both running the same version of powershell, (4      0      -1     -1      )

    both with the same executionpolicy set (Bypass at the moment)

    i run a script to call a secondary script with different credentials on server one it works fine, copy these two scripts to server two (identical locations) and i get an error.

    script:

    $userCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "mydomain\myaccount", $pswd

    start-process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File C:\mypath\Script2.ps1" -Credential $userCredential -windowstyle Hidden

    the error 

    start-process : This command cannot be run due to the error: The system cannot find the file specified.
    At C:\GPFolder\Scripts\Usercontrol\launch.ps1:5 char:1
    + start-process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.e ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

    if i remove the credentials start-process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File C:\mypath\Script2.ps1" #-Credential $userCredential -windowstyle Hidden

    it works, any thoughts?

    Friday, September 15, 2017 2:16 PM

All replies

  • Hi,

    This is a quick note to let you know that I am currently performing research on this issue and will get back to you as soon as possible. I appreciate your patience.

    If you have any updates during this process, please feel free to let me know.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, September 18, 2017 8:47 AM
  • Hi,

    This is not a normal behavior. In order to provide efficient method for troubleshooting, I would like to confirm the following questions:
    >> start-process : This command cannot be run due to the error: The system cannot find the file specified.
    At C:\GPFolder\Scripts\Usercontrol\launch.ps1:5 char:1
    Can you find out this location on both your server 1 and server 2? –“ C:\GPFolder\Scripts\Usercontrol\launch.ps1”

    >> if i remove the credentials start-process -FilePath "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-File C:\mypath\Script2.ps1" #-Credential $userCredential -windowstyle Hidden
    Did they use the same domain account?  Does this account has privileges on server2?

    Please open control panel, selected user account, temporary close the UAC to see if it helps.

    If you need further help, please feel free to let us know.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, September 19, 2017 10:17 AM
  • Hi,

    Just want to confirm the current situations. Have you tried the method which provided before?

    If you already tried them or the issue remains after trying them, please don’t hesitate to tell me. I will do more research and try my best to give you helpful suggestions.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, September 22, 2017 6:02 AM
  • Sorry for the delay i have been away.

    if i remove the -credential, it runs under my account and works fine.

    UAC is turned off currently, both my account and the account i am trying to run the process as are domain admins.

    i have copied my account and tried to run the process as the copy and it fails

    John

    Thursday, September 28, 2017 12:06 PM
  • Hi,

    >> i run a script to call a secondary script with different credentials on server one it works fine, copy these two scripts to server two (identical locations) and i get an error.
    Based on my research, I recommend you could have a try to put the scripts to another drive's root path to see if the issue still remains.

    Appreciate for your feedback.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, October 3, 2017 10:50 AM
  • PsCredential requires a SecureString for the password.

    \_(ツ)_/

    Tuesday, October 3, 2017 11:54 AM
  • Hi,

    Just want to confirm the current situations.

    If you already tried them or the issue remains after trying them, please don’t hesitate to tell me. I will do more research and try my best to give you helpful suggestions.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, October 5, 2017 8:48 AM