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