after trying several possibilities I'am not sure how to continue.
I need to execute a script "C:\test1\script.ps1"
And I need to pass some Arguments with this script too. These Arguments (-Hashtag $Hashtag -Name $Name
and so on...) are stored in a Variable called $arguments
.
So the final call should look like : C:\test1\script.ps1 $arguments
That is no problem, but now the thing I can't get managed to work.
My goal is to execute this as a different user. The Login credentials are stored in $cred
I already tried the following things compared to related topics here in the forums:
Command
Invoke-Command -Credential $cred -Authentication Credssp -ComputerName home -ScriptBlock {C:\test1\script.ps1 $arguments}
Powershell Result: Some of the arguments (in this case the Hashtag) is empty. Im not sure why this happens cause I just filled the $arguments Variable with all the stuff.
Command
Start-Process -FilePath "C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe" -ArgumentList "C:\test1\script.ps1 $arguments -Credential $cred -WorkingDirectory 'C:\\Windows\System32'
This results that the Script won't get executed.
Does anyone have some more info about handling that construction? Maybe there is another Command I can pass credentials to?
As another notice, I cant use Credential Prompts so any solutions where UAC get into consideration is not suitable for my problem.