0

I created the below code & its getting failed because of the access denied error for start process while executing powershell.exe.

$username = "domain\username"

$password = "Welcome1234$"

$PSArgs = "D:\test.ps1"

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential $username,

$securePassword

Start-Process Powershell.exe -Credential $credential $PSArgs

Error:

Start-Process : This command cannot be executed due to the error: Access is denied  
Start-Process : This command cannot be executed due to the error: Access is denied.
At C:\Windows\system32\config\systemprofile\AppData\Local\Temp\PRISMA-AMR-JOB1-87-ScriptBuildTask-8569094554411403512.ps1:38 char:18
+     Start-Process <<<<  C:\Windows\System32\cmd.exe -arg "/C" -Credential $credential + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Wayne Yang
  • 9,016
  • 2
  • 20
  • 40
hans
  • 41
  • 1
  • 10

1 Answers1

0

Start-Process : This command cannot be executed due to the error: Access is denied. At C:\Windows\system32\config\systemprofile\AppData\Local\Temp\PRISMA-AMR-JOB1-87-ScriptBuildTask-8569094554411403512.ps1:38 char:18

According to this error code, it seems you have not add your user "domain\username" to local computer policy -> User Rights Assignment.

enter image description here

More information about User Rights Assignment, please refer to this link.

Also, here a similar case, please refer to it.

Note:

To open the Local Group Policy, at a command prompt or in Search, type gpedit.msc, and then click OK or press ENTER.

Jason Ye
  • 13,710
  • 2
  • 16
  • 25