Skip to content

Instantly share code, notes, and snippets.

@brianbolger
Created March 9, 2012 15:45
Show Gist options
  • Save brianbolger/2007169 to your computer and use it in GitHub Desktop.
Save brianbolger/2007169 to your computer and use it in GitHub Desktop.
Check a list of machines for PowerShell remoting access
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