Enter-PSSession é exclusivamente para uso interativo.
Para testar se a comunicação remota está ativada, use New-PSSession :
$testSession = New-PSSession -Computer $targetComputer
if(-not($testSession))
{
Write-Warning "$targetComputer inaccessible!"
}
else
{
Write-Host "Great! $targetComputer is accessible!"
Remove-PSSession $testSession
}
Se for bem-sucedido, New-PSSession retornará o novo objeto PSSession - se ele falhar, não retornará nada e $testSession será $null (tornando -not($testSession) -eq $true )