gangstanthony

Untitled

Jan 29th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Create the function to test if a registry key exists
  2. function Test-RegKey {
  3.     param (
  4.         $ComputerName = $env:COMPUTERNAME,
  5.         $Hive = 'LocalMachine',
  6.         $Key
  7.     )
  8.  
  9.     try {
  10.         $regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive, $ComputerName)
  11.         $ref = $regKey.OpenSubKey($Key)
  12.    
  13.         if (!$ref) {
  14.             $false
  15.         } else {
  16.             $true
  17.         }
  18.     } catch {
  19.         $null
  20.     }
  21. }
  22.  
  23. # gotta get your computers from somewhere, right?
  24. #$computers = ipcsv c:\temp\listofcomputers.csv
  25.  
  26. # or we'll just use this for test purposes
  27. $computers = [pscustomobject]@{
  28.     Name = $env:COMPUTERNAME
  29. }
  30.  
  31. $results = $computers | % {
  32.     $ping = New-Object System.Net.NetworkInformation.Ping
  33.     $total = $computers.Count
  34.     $starttime = $lasttime = Get-Date
  35.     $index = 0
  36. } {
  37.     $index++
  38.     $currtime = (Get-Date) - $starttime
  39.     $avg = $currtime.TotalSeconds / $index
  40.     $last = ((Get-Date) - $lasttime).TotalSeconds
  41.     $left = $total - $index
  42.     Write-Progress `
  43.         -Activity ((
  44.             "Check for OfficeScan $(Get-Date -f yyyy-MM-dd_HH:mm:ss)",
  45.             "Total: $($currtime -replace '\..*')",
  46.             "Avg: $('{0:N2}' -f $avg)",
  47.             "Last: $('{0:N2}' -f $last)",
  48.             "ETA: $('{0:N2}' -f (($avg * $left) / 60))",
  49.             "min ($([string](Get-Date).AddSeconds($avg*$left) -replace '^.* '))"
  50.         ) -join ' ') `
  51.         -Status "$index of $total ($left left) [$('{0:N2}' -f (($index/$total)*100))%]" `
  52.         -CurrentOperation "COMP: $($_.Name)" `
  53.         -PercentComplete (($index/$total)*100)
  54.     $lasttime = Get-Date
  55.  
  56.     $pingresult = try{ $ping.Send($_.Name, 750) }catch{}
  57.     if ($pingresult.Status -eq 'Success') {
  58.         $resultx86 = Test-RegKey -ComputerName $_.Name -Key 'SOFTWARE\TrendMicro\PC-cillinNTCorp\CurrentVersion\HotfixHistory\11.0\CP_4150'
  59.         $resultx64 = Test-RegKey -ComputerName $_.Name -Key 'SOFTWARE\Wow6432Node\TrendMicro\PC-cillinNTCorp\CurrentVersion\HotfixHistory\11.0\CP_4150'
  60.     } else {
  61.         $resultx86 = $resultx64 = 'Offline'
  62.     }
  63.  
  64.     [pscustomobject]@{
  65.         ComputerName = $_.Name
  66.         HasOfficeScanx86 = $resultx86
  67.         HasOfficeScanx64 = $resultx64
  68.     }
  69. }
  70.  
  71. $results
  72.  
  73. $results | epcsv c:\temp\results.csv -not
Advertisement
Add Comment
Please, Sign In to add comment