Would you possibly know why this error is being raised in response to the code below. User-name and password have been verified as correct.
$secPassword = ConvertTo-SecureString "Password" -AsPlaintext -Force
$farmCredential = New-Object System.Management.Automation.PsCredential "SharePointSP_Farm",$secPassword
Start-Process $PSHOMEpowershell.exe -Credential $FarmCredential -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `"Hello:`"`$outvar1`"}`"" -Wait
the error;
Start-Process : This command cannot be executed due to the error: The directory name is invalid.
At C:UsersAdministrator.SHAREPOINTAppDataLocalTempfb2956d7-87fc-4235-9f3c-742698cafe9f.ps1:8 char:14
+ Start-Process <<<< $PSHOMEpowershell.exe -Credential $FarmCredential -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output
`"Hello:`"`$outvar1`"}`"" -Wait
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
however, this works just fine.
Start-Process $PSHOMEpowershell.exe -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `"Hello:`"`$outvar1`"}`"" -Wait
NOTE: this is when executing from within PowerGUI or the ISE ide's
The file fb2956d7-87fc-4235-9f3c-742698cafe9f.ps1 does exist at the path location, so for some reason the ide is having dificulty with this. Yet it DOES work when ran directly within the power shell command prompt/shell.
I was logged in with a local machine account that is running as local admin, the script directs execution to a domain account which does not have admin rights and would run with just user permissions.
Is this a bug, since as a developer the IDE should not be tripped up by this as it works when i run the block in the powershell command prompt window??
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…