Advertisement
gangstanthony

creating-a-array-of-info-for-remote-computers

Apr 18th, 2016
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # http://powershell.org/wp/forums/topic/creating-a-array-of-info-for-remote-computers/
  2.  
  3. function Get-JavaVersion ($computer = $env:COMPUTERNAME) {
  4.     $version = 0
  5.  
  6.     $keyname = 'SOFTWARE\JavaSoft\Java Web Start'
  7.    
  8.     $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
  9.     $key = $reg.OpenSubkey($keyname)
  10.    
  11.     try {
  12.         $version = $key.GetValue('CurrentVersion')
  13.     } catch {}
  14.    
  15.     return $version
  16. }
  17.  
  18. function Get-LoggedInUser ($computer = $env:COMPUTERNAME) {
  19.     $owners = @{}
  20.     Get-WmiObject win32_process -ComputerName $computer -Filter 'name = "explorer.exe"' | % {$owners[$_.handle] = $_.getowner().user}
  21.     return Get-Process -ComputerName $computer explorer | % {$owners[$_.id.tostring()]}
  22. }
  23.  
  24. function Get-OfficeVersion ($computer = $env:COMPUTERNAME) {
  25.     $version = 0
  26.  
  27.     $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
  28.  
  29.     try {
  30.         $reg.OpenSubKey('SOFTWARE\Microsoft\Office').GetSubKeyNames() | % {
  31.             if ($_ -match '(\d+)\.') {
  32.                 if ([int]$matches[1] -gt $version) {
  33.                     $version = $matches[1]
  34.                 }
  35.             }
  36.         }
  37.     } catch {}
  38.  
  39.     return $version
  40. }
  41.  
  42. function Get-IPAddress ($computer = $env:COMPUTERNAME) {
  43.     return (Test-Connection $computer -Count 1).IPV4Address.tostring()
  44. }
  45.  
  46. function Get-IEVersion ($computer = $env:COMPUTERNAME) {
  47.     $version = 0
  48.    
  49.     $keyname = 'SOFTWARE\Microsoft\Internet Explorer'
  50.      
  51.     $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
  52.     $key = $reg.OpenSubkey($keyname)
  53.    
  54.     try {
  55.         $version = $key.GetValue('Version')
  56.         $svcUpdateVersion = $key.GetValue('svcUpdateVersion')
  57.     } catch {}
  58.  
  59.     if ($svcUpdateVersion) {
  60.         return $svcUpdateVersion
  61.     } else {
  62.         return $version
  63.     }
  64. }
  65.  
  66. # script entry point
  67. $computernames = Get-Content C:\Users\ppagal\Desktop\computers.txt
  68.  
  69. $results = foreach ($computer in $computernames) {
  70.     if (Test-Connection $computer -Count 2 -Quiet) {
  71.         [pscustomobject]@{
  72.             ComputerName = $computer
  73.             IPAddress = Get-IPAddress $computer
  74.             LoggedInUser = Get-LoggedInUser $computer
  75.             OfficeVersion = Get-OfficeVersion $computer
  76.             IEVersion = Get-IEVersion $computer
  77.             JavaVersion = Get-JavaVersion $computer
  78.         }
  79.     } else {
  80.         [pscustomobject]@{
  81.             ComputerName = $computer
  82.             IPAddress = '-'
  83.             LoggedInUser = '-'
  84.             OfficeVersion = '-'
  85.             IEVersion = '-'
  86.             JavaVersion = '-'
  87.         }
  88.     }
  89. }
  90.  
  91. $results | Format-Table -AutoSize
  92.  
  93. $results | Export-Csv c:\temp\report.csv -NoTypeInformation
Advertisement
RAW Paste Data Copied
Advertisement