Run ScriptBlock with different credentials

I have a script that defines a user ID, as soon as I have this user ID, I want to run a script block against this user using different credentials. Is it possible? Can someone show me examples of this? I appreciate it. Thank you in advance.: -)

+4
source share
2 answers

I got it, thanks to Trevor Sullivan for pointing me in the right direction. I ended up just putting my second ps1 file in the script block and running it as a job and passing arguments to it from the main script, like this

$job = Start-Job -scriptblock {
param ($username)
some code to run against the variable that was passed in
} -Args $target -credential $Cred

$target - , -. $ username - , .

+9

. . ( ) .

Invoke-Command, , -Credential , , uri . -Credential Start-Job, .

0

Source: https://habr.com/ru/post/1523647/


All Articles