Skip to content

Instantly share code, notes, and snippets.

@SweetAsNZ
Created February 7, 2022 03:05
Show Gist options
  • Save SweetAsNZ/cbcfe2390462b8b49039a64c4d50bd3b to your computer and use it in GitHub Desktop.
Save SweetAsNZ/cbcfe2390462b8b49039a64c4d50bd3b to your computer and use it in GitHub Desktop.
Get All Unique Desktop OS's With Numbers of Each
function Get-DesktopsOS {
"`r"
$PCs = Get-ADComputer -Filter * -Properties Name,OperatingSystem,Enabled -ResultSetSize 1000000 |
Where-Object {($_.OperatingSystem -like "Windows*") -and ($_.OperatingSystem -notlike "Windows Server*")} |
Select-Object Name,Enabled,OperatingSystem | Sort-Object Name
$UniquePCs = ($PCs | Where {($_.Enabled -eq $true)}).OperatingSystem | Sort-Object | Get-Unique -AsString
Write-Host 'Enabled PCs: ' -ForegroundColor Green
foreach($PCOS in $UniquePCs){
$PCOS ; ( Get-ADComputer -Filter * -Properties Name,OperatingSystem | Where {($_.OperatingSystem -eq $PCOS)} ).count
"`r" # Carriage Return
}
Write-Host "Total Enabled PCs: " -ForegroundColor YELLOW ; ($PCs | Where {$_.Enabled -eq $true}).count
Write-Host "Total PCs Including Disabled: " -ForegroundColor YELLOW ; $PCs.count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment