如果启用CredSSP,我在尝试检查远程计算机列表时遇到问题。当我的脚本连接到计算机并执行命令时。它最终返回false。如果我通过RDP连接到同一台机器并执行相同的命令,它将返回true。这是我的剧本:
foreach ($server in $servers.Split(",").Trim()) {
$pw = ConvertTo-SecureString 'password' -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentList "Domain\user", $pw
$session = New-PSSession -ComputerName $server -Credential $cred
$output = (Get-Item WSMan:\localhost\Service\Auth\CredSSP).value
Write-Host $server : $output
Remove-PSSession -Session $session
}
有没有人对此有所了解?
答案 0 :(得分:1)
您没有远程运行Get-Item
。
尝试:
$ServerList = $servers.Split(",").Trim();
$pw = ConvertTo-SecureString 'password' -AsPlainText -Force;
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentList "Domain\user", $pw;
Invoke-Command -ComputerName $ServerList -Credential $cred -ScriptBlock { Get-Item WSMan:\localhost\Service\Auth\CredSSP; } |
Select-Object PSComputerName, Value;
您可以使用Invoke-Command -Session $session
代替Invoke-Command -ComputerName $ServerList
,但无需手动制作和删除会话,无需循环播放。