Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://powershell.org/wp/forums/topic/creating-a-array-of-info-for-remote-computers/
- function Get-JavaVersion ($computer = $env:COMPUTERNAME) {
- $version = 0
- $keyname = 'SOFTWARE\JavaSoft\Java Web Start'
- $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
- $key = $reg.OpenSubkey($keyname)
- try {
- $version = $key.GetValue('CurrentVersion')
- } catch {}
- return $version
- }
- function Get-LoggedInUser ($computer = $env:COMPUTERNAME) {
- $owners = @{}
- Get-WmiObject win32_process -ComputerName $computer -Filter 'name = "explorer.exe"' | % {$owners[$_.handle] = $_.getowner().user}
- return Get-Process -ComputerName $computer explorer | % {$owners[$_.id.tostring()]}
- }
- function Get-OfficeVersion ($computer = $env:COMPUTERNAME) {
- $version = 0
- $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
- try {
- $reg.OpenSubKey('SOFTWARE\Microsoft\Office').GetSubKeyNames() | % {
- if ($_ -match '(\d+)\.') {
- if ([int]$matches[1] -gt $version) {
- $version = $matches[1]
- }
- }
- }
- } catch {}
- return $version
- }
- function Get-IPAddress ($computer = $env:COMPUTERNAME) {
- return (Test-Connection $computer -Count 1).IPV4Address.tostring()
- }
- function Get-IEVersion ($computer = $env:COMPUTERNAME) {
- $version = 0
- $keyname = 'SOFTWARE\Microsoft\Internet Explorer'
- $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
- $key = $reg.OpenSubkey($keyname)
- try {
- $version = $key.GetValue('Version')
- $svcUpdateVersion = $key.GetValue('svcUpdateVersion')
- } catch {}
- if ($svcUpdateVersion) {
- return $svcUpdateVersion
- } else {
- return $version
- }
- }
- # script entry point
- $computernames = Get-Content C:\Users\ppagal\Desktop\computers.txt
- $results = foreach ($computer in $computernames) {
- if (Test-Connection $computer -Count 2 -Quiet) {
- [pscustomobject]@{
- ComputerName = $computer
- IPAddress = Get-IPAddress $computer
- LoggedInUser = Get-LoggedInUser $computer
- OfficeVersion = Get-OfficeVersion $computer
- IEVersion = Get-IEVersion $computer
- JavaVersion = Get-JavaVersion $computer
- }
- } else {
- [pscustomobject]@{
- ComputerName = $computer
- IPAddress = '-'
- LoggedInUser = '-'
- OfficeVersion = '-'
- IEVersion = '-'
- JavaVersion = '-'
- }
- }
- }
- $results | Format-Table -AutoSize
- $results | Export-Csv c:\temp\report.csv -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement