Created
February 7, 2022 03:05
-
-
Save SweetAsNZ/cbcfe2390462b8b49039a64c4d50bd3b to your computer and use it in GitHub Desktop.
Get All Unique Desktop OS's With Numbers of Each
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
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