windows – 测试Enter-PSSession是否成功

前端之家收集整理的这篇文章主要介绍了windows – 测试Enter-PSSession是否成功前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法测试Enter-PSSession是否成功或Enable-Remoting是否已经存在?我不需要能够进入机器本身,只是找出返回代码方法.基本上,只需检查是否可以进行远程连接到机器,或者机器是否仍需要启用远程处理.
Enter-PSSession专门用于交互式使用.

要测试是否启用了远程处理,请使用New-PSSession

$testSession = New-PSSession -Computer $targetComputer
if(-not($testSession))
{
    Write-Warning "$targetComputer inaccessible!"
}
else
{
    Write-Host "Great! $targetComputer is accessible!"
    Remove-PSSession $testSession
}

如果成功,New-PSSession将返回新的PSSession对象 – 如果失败则不返回任何内容,$testSession为$null(因此使-not($testSession)-eq $true)

原文链接:https://www.f2er.com/windows/368342.html

猜你在找的Windows相关文章