0

我正在尝试在远程计算机上运行脚本块,但不会提示我输入凭据,我想在脚本中传递它们。某些命令可能,但除非我提供凭据,否则我要运行的命令被拒绝访问。

例如这个命令可以工作:

Invoke-Command -Session $session -ErrorAction Stop -ErrorVariable $Error -Scriptblock {ls }

但这不会起作用,除非通过 -credential (Invoke-Command on target)

Invoke-Command -Session $session -ErrorAction Stop -ErrorVariable $Error -Scriptblock {Invoke-Command -computername $Env:COMPUTERNAME -Credential $Cred  -ScriptBlock {ls} }

我想要实现的同样方式导致访问被拒绝问题(启动进程)

Invoke-Command -Session $session -ErrorAction Stop -ErrorVariable $Error -Scriptblock {[System.Diagnostics.Process]::Start("C:\Myprocess.exe", $localArgs, "UserName", $credential.Password, "MyDomain")}
4

1 回答 1

0
   Invoke-Command -Session $session -ErrorAction Stop -ErrorVariable $setError -Scriptblock {$Domain = "domain";$PassSec = ConvertTo-SecureString $( "password") -AsPlainText -Force ; $Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $($domain + "\" + "userName"),$passSec; Invoke-Command -computername $Env:COMPUTERNAME -Credential $Cred  -ScriptBlock {C:\Myprocess.exe } }
于 2013-11-05T19:26:05.730 回答