none
Powershell passing credentials RRS feed

  • Frage

  • I am unable to pass credentials with the following script.  If I take out the credentials, $cred, it works OK.  However I need to run this with the added credentials.  

    $domain= "Domain1.pvt" 
    $password= ConvertTo-SecureString "Password" -asPlainText -Force 
    $user= "$domain\User1" 
    $cred= New-Object System.Management.Automation.PSCredential ($user,$password) 
    $File = ".\file.exe"
    $Path = '\\server\folder\' 
    $Arg = '/S'
    Start-Process -filepath $File -WorkingDirectory $Path -Credential $cred

    This errors with the following:

    Start-Process : This command cannot be run due to the error: The system cannot find the file specified.

    Tried ... Inserting the user to prompt.  This prompts OK, but still same error.

    $domain= "Domain1.pvt" 
    $password= ConvertTo-SecureString "Password" -asPlainText -Force 
    $user= "$domain\User1" 
    $cred= New-Object System.Management.Automation.PSCredential ($user,$password) 
    $File = ".\file.exe"
    $Path = '\\server\folder\' 
    $Arg = '/S'
    Start-Process -filepath $File -WorkingDirectory $Path -Credential Domain.pvt\User1

    Tried ... Changing the pathing variables.  Again, this works only if I remove the $cred variable.  

    $domain= "Domain1.pvt" 
    $password= ConvertTo-SecureString "Password" -asPlainText -Force 
    $user= "$domain\User1" 
    $cred= New-Object System.Management.Automation.PSCredential ($user,$password) 
    Start-Process -filepath "file.exe" -WorkingDirectory "\\server\folder" -Credential $cred

    -or-

    $domain= "Domain1.pvt" 
    $password= ConvertTo-SecureString "Password" -asPlainText -Force 
    $user= "$domain\User1" 
    $cred= New-Object System.Management.Automation.PSCredential ($user,$password) 
    Start-Process -filepath "\\server\folder\file.exe" -Credential $cred

    Doesn't matter how chance up the variable or remove the, as soon as I add -credential it errors.  The user is an Admin.

    Thoughts?


    Mittwoch, 22. Januar 2020 14:53

Alle Antworten

  • Please edit and fix your post:

    See the following for instructions:


    \_(ツ)_/

    Mittwoch, 22. Januar 2020 15:16
    Moderator
  • Clearly the file cannot be accessed by the user whose credentials you are using.

    You will need to post all error messages in their complete form as more info is available.


    \_(ツ)_/


    Mittwoch, 22. Januar 2020 15:19
    Moderator
  • Hi,

    Please try to check the \\server\folder\file.exe permissions.Then save to $cred variable using a user account with execute permission.

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


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

    Montag, 27. Januar 2020 08:38
    Moderator