Skip to content

Instantly share code, notes, and snippets.

@nshores
Last active October 31, 2018 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/bc2b171cf99d2add44a6a477ee1dbccd to your computer and use it in GitHub Desktop.
Save nshores/bc2b171cf99d2add44a6a477ee1dbccd to your computer and use it in GitHub Desktop.
comp_report.ps1
$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