Start-Process: Access is denied (even though i've provided credentials

12,782

Q: Have you tried without the "-wait"?

Look at this link:

The parameter "-wait" suppresses the command prompt or retains the window until the process completes. This operation may require administrator rights.

Share:
12,782
mhopkins321
Author by

mhopkins321

Updated on July 26, 2022

Comments

  • mhopkins321
    mhopkins321 almost 2 years

    I am getting the following error when trying to execute a line of code

    Start-Process : This command cannot be executed due to the error: 
    Access is denied.
    

    This is the code being executed

    $username = "domain\username"
    $passwordPlainText = "password"     
    $password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password
    
    $powershellArguments = "D:\path\ps.script.ps1", "arg1", "arg2", "arg3", "arg4"
    Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments -wait
    
    • This code works fine when executed locally, but not when called via vbs WMI
    • Both computers exist in the same domain and address range
    • The username and password supplied have admin privileges on both machines
    • I have tried both with and without -wait however neither works, and due to the user being privileged, I'd prefer to keep it
  • mhopkins321
    mhopkins321 over 11 years
    however, even with -wait, the username and password i'm using have full access to the box, so it shouldn't be an issue that it requires admin rights