Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $machines = Get-ADComputer -SearchBase "DOMAIN OU" -Filter {Enabled -eq $true} | Foreach {$_.DNSHostName}
  2. $Output=ForEach ($System in $Machines) {
  3.     $app = $null
  4.     $ServerStatus = "Unreachable"
  5.     $AppStatus = "Presense Unknown"
  6.  
  7.     if (!(test-Connection -ComputerName $System -BufferSize 16 -Count 1 -ea 0 -Quiet))
  8.     {
  9.         Write-Output "$System Offline"
  10.     }
  11.     Else
  12.     {
  13.          Try {
  14.             $app = Get-WMIObject -Class win32_product -Filter {Name like "Sophos Anti-Virus"} -ComputerName $System -ErrorAction STOP
  15.             $ServerStatus = "Online"
  16.            
  17.             if($app) {
  18.                 $AppStatus = "Present"
  19.             } else {
  20.                 $AppStatus = "Not Present"
  21.             }
  22.              
  23.          }
  24.          Catch {
  25.                 Write-Output "$system Offline "
  26.  
  27.          }
  28.     }
  29.  
  30.     if($app) {
  31.          $app | Select-Object -Property @{n="ComputerName";e={$System}},@{n="ServerStatus";e={$ServerStatus}},@{n="AppStatuName";e={$AppStatus}},Name,Version
  32.     } else {
  33.          "" | Select-Object -Property @{n="ComputerName";e={$System}},@{n="ServerStatus";e={$ServerStatus}},@{n="AppStatuName";e={$AppStatus}},Name,Version  
  34.     }
  35. }
  36.  
  37. $output | Export-csv C:\Output.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement