PowerShell: Check a List of Windows Computers for Online & Offline Statuses

# checkOnlineComputers.ps1

# Set a list of computers in a text file
$computerListFile='C:\Temp\computerlist.txt'

# Read the computer list and run SMB tests against each one
$content=get-content $computerListFile
$results=[hashtable]@{}
foreach ($line in $content){
  $smbReach=test-path "\\$($line.trim())\C$\Windows"
  write-host "$line`: $smbReach"
  #pause
  $results+=@{$line=$smbReach}
  }

# Display the results
$results.GetEnumerator() | ?{!$_.value} | %{
    $message = '{0}: {1}' -f $_.key, $_.value
    Write-Output $message
}  

Leave a Reply

Your email address will not be published. Required fields are marked *