8,330 questions
Start-Process System.InvalidOperationException: This command cannot be run due to the error: The handle is invalid.
Horacio
1
Reputation point
I have a task that is running with NETWORK SERVICE account that is calling a ps1, the ps1 is calling Start-Process with credentials, the arguments for the actions in the task are: -Version "5.0" -Noninteractive -Noprofile -WindowStyle "Hidden" -Command "& 'C:\Dev\Connectv3\connect-reports\PSScripts\StartProcess.ps1'", the settings of the task:
And the code
ry {
Start-Transcript -Path "$($PSScriptRoot)\StartProcess.log"
$user = "DOMAIN\userName"
$pswd = "Password" | ConvertTo-SecureString -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $user,$pswd
$workingDirectory = $PSScriptRoot
$commandlet = "$($PSScriptRoot)\StartProcessDummy.ps1"
#a) StartProcess
$commandlet = "'" + $commandlet + "'"
$argList = "$commandlet"
$argList = ' -Version "5.0" -NoProfile -WindowStyle "Hidden" -Command "& '+ $argList + """"
Write-Host $argList
Start-Process -FilePath powershell.exe -ArgumentList $argList -Credential $credentials -Verbose -Wait -RedirectStandardError "StartProcessErrors.log" -WorkingDirectory $PSHOME
}
catch {
$_ | format-list -force | Out-String
throw
}
finally{
Stop-Transcript
}
Windows for business Windows Server User experience PowerShell
Sign in to answer