我试图使用New-PSSession
运行循环并以管理员身份运行,但我收到错误。
foreach ($c in $targets) {
$s = New-PSSession -ComputerName $c -Credential cred
Invoke-Command -Session $s -ScriptBlock {gci C:\temp} -RunAsAdministrator
}
我收到以下错误:
Invoke-Command:无法使用指定的命名参数解析参数集。
发生错误是因为-Session
参数不能与-RunAsAdministrator
参数同时使用。