Last active
October 31, 2018 18:51
-
-
Save nshores/bc2b171cf99d2add44a6a477ee1dbccd to your computer and use it in GitHub Desktop.
comp_report.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$computers = Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -first 20 | |
$CompCollection=@() | |
foreach ($c in $computers){ | |
#define custom object | |
write-host "Checking $($c.name)" | |
$CompCurrent = New-Object -TypeName psobject | |
$CompCurrent | Add-Member -MemberType NoteProperty -Name ComputerName -Value "" | |
$CompCurrent | Add-Member -MemberType NoteProperty -Name OSArchitecture -Value "" | |
$CompCurrent | Add-Member -MemberType NoteProperty -Name OperatingSystemServicePack -Value "" | |
$CompCurrent | Add-Member -MemberType NoteProperty -Name OperatingSystemVersion -Value "" | |
#Catch errors | |
try{ | |
$compos = gwmi -ComputerName $c.name win32_operatingsystem -ErrorAction Stop | select osarchitecture | |
} | |
catch{ | |
$compos.osarchitecture = 'Machine Unreachable' | |
} | |
#populate custom object | |
$CompCurrent.computername = $c.name | |
$CompCurrent.OSArchitecture = $compos.osarchitecture | |
$CompCurrent.OperatingSystemServicePack = $c.OperatingSystemServicePack | |
$CompCurrent.OperatingSystemVersion = $c.OperatingSystemVersion | |
$CompCollection += $CompCurrent | |
} | |
$CompCollection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment