AD Computers - Count OS Version by OU RRS feed

  • Question

  • Goal: Count computer objects in AD by OU, by OperatingSystemVersion, across multiple domains. Return output should include the following: Domain | OU Name | Operating System Name | Operating System Version | Count

    I have a skeleton script created , but I'm having difficulty getting the counts split by OS version. I'm working with group-object, which does get the counts by OS version, but I'm not sure what the best way is to output those values in the table above.

    Import-Module -Name ActiveDirectory
    $Output = @()
    $Domains = ("abc.contoso.com","def.contoso.com","ghi.contoso.com")
    foreach ($DC in $Domains) {
        $OUs = Get-ADOrganizationalUnit -Filter * -Server $DC -Properties Description, DistinguishedName
        Foreach ($OU in $OUs) {
            $Computers = Get-ADComputer -Filter {Enabled -eq "true"} -Server $DC -SearchBase $OU -Properties Name, Enabled, OperatingSystem, OperatingSystemVersion | select Name, Enabled, OperatingSystem, OperatingSystemVersion
            Write-Output "Scanning OU: $($OU.DistinguishedName)"
            $OutputItem = New-Object PSObject;
            $OutputItem | Add-Member NoteProperty "Domain" $DC
    		$OutputItem | Add-Member NoteProperty "OU Name" $OU.Name
    		$OutputItem | Add-Member NoteProperty "OperatingSystem" $NEEDHELP
    		$OutputItem | Add-Member NoteProperty "OperatingSystemVersion" $NEEDHELP
    		$OutputItem | Add-Member NoteProperty "Count" 
            $Output += $OutputItem
    $Output | Out-GridView

    Wednesday, June 13, 2018 8:58 PM

All replies

  • $output | group 'OU Name'

    The opinion expressed by me is not an official position of Microsoft

    Wednesday, August 8, 2018 7:52 AM