PowerShell远程会话变量无法正常工作

问题描述 投票:0回答:1

我试图使用New-PSSession运行循环并以管理员身份运行,但我收到错误。

foreach ($c in $targets) {
    $s = New-PSSession -ComputerName $c -Credential cred
    Invoke-Command -Session $s -ScriptBlock {gci C:\temp} -RunAsAdministrator
}

我收到以下错误:

Invoke-Command:无法使用指定的命名参数解析参数集。

powershell powershell-remoting
1个回答
3
投票

发生错误是因为-Session参数不能与-RunAsAdministrator参数同时使用。

© www.soinside.com 2019 - 2024. All rights reserved.