Created
March 9, 2012 15:45
-
-
Save brianbolger/2007169 to your computer and use it in GitHub Desktop.
Check a list of machines for PowerShell remoting access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CheckMachineForRemoteAccess() | |
{ | |
$enabled | |
$session | |
try | |
{ | |
$ErrorActionPreference = 'SilentlyContinue' | |
$session = New-PSSession -ComputerName $_ | |
$enabled = $session.Availability | |
Remove-PSSession -session $session | |
} | |
catch [system.exception] | |
{ | |
$enabled = "Unavailable" | |
} | |
finally | |
{ | |
if ($enabled -eq 'Available') | |
{ | |
Write-Host $_ : remote sessions "$enabled" -fore green | |
} | |
else | |
{ | |
Write-Host $_ : remote sessions "$enabled" -fore red | |
} | |
} | |
} | |
@( | |
'machine1', | |
'machine2' | |
) | foreach { CheckMachineForRemoteAccess } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment