检查CredSSP是否已远程启用Powershell

时间:2016-08-04 19:59:41

标签: powershell-v3.0 credssp

如果启用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
}

有没有人对此有所了解?

1 个答案:

答案 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,但无需手动制作和删除会话,无需循环播放。