Connect-MgGraph -NoWelcome $Devices = Get-MgDeviceManagementManagedDevice -All $MacOsTotal = 0 $WindowsTotal = 0 $WindowsLatestCount = 0 $WindowsOtherCount = 0 $MacOsLatestCount = 0 $MacOsOtherCount = 0 $MacOsDevices = @{} $WindowsDevices = @{} ForEach($Device in $Devices) { If($Device.OperatingSystem -like "Windows") { $WindowsTotal += 1 If($WindowsDevices[$Device.OSVersion]) { $WindowsDevices[$Device.OSVersion] += 1 } Else { $WindowsDevices.Add($Device.OSVersion,1) } If($Device.OSVersion -like "10.0.2*") { $WindowsLatestCount += 1 } Else { $WindowsOtherCount += 1 } } ElseIf($Device.OperatingSystem -like "macOS") { $MacOsTotal += 1 If($MacOsDevices[$Device.OSVersion]) { $MacOsDevices[$Device.OSVersion] += 1 } Else { $MacOsDevices.Add($Device.OSVersion,1) } If($Device.OSVersion -like "15.*") { $MacOsLatestCount += 1 } Else { $MacOsOtherCount += 1 } } } $WindowsResults = $WindowsDevices.GetEnumerator() | Sort-Object -Property Name -Descending $MacOsResults = $MacOsDevices.GetEnumerator() | Sort-Object -Property Name -Descending "
" "There are $WindowsTotal managed Windows devices:" "
| Version | Number of devices |
|---|---|
| $($Result.Name) | $($Result.Value) |
| $($Result.Name) | $($Result.Value) |
There are $MacOsTotal managed macOS devices:" "
| Version | Number of devices |
|---|---|
| $($Result.Name) | $($Result.Value) |
| $($Result.Name) | $($Result.Value) |