Added a filter to the version reporting script. Only clients that have been online in the last 30 days will be shown.

This commit is contained in:
Thomas De Reyck
2026-08-06 10:12:06 +02:00
parent df13809a3a
commit a181d5dc9d
@@ -1,3 +1,5 @@
$Today = Get-Date
Connect-MgGraph -NoWelcome
$Devices = Get-MgDeviceManagementManagedDevice -All
@@ -15,6 +17,12 @@ $MacOsDevices = @{}
$WindowsDevices = @{}
ForEach($Device in $Devices) {
If($Device.LastSyncDateTime.AddDays(30) -lt $Today) {
# Device has not checked in for a month. Not including it in report.
Continue
}
If($Device.OperatingSystem -like "Windows") {
$WindowsTotal += 1
If($WindowsDevices[$Device.OSVersion]) {
@@ -23,7 +31,7 @@ ForEach($Device in $Devices) {
$WindowsDevices.Add($Device.OSVersion,1)
}
If($Device.OSVersion -like "10.0.2*") {
If($Device.OSVersion -like "10.0.262*") {
$WindowsLatestCount += 1
} Else {
$WindowsOtherCount += 1
@@ -37,7 +45,7 @@ ForEach($Device in $Devices) {
$MacOsDevices.Add($Device.OSVersion,1)
}
If($Device.OSVersion -like "15.*") {
If($Device.OSVersion -like "26.*") {
$MacOsLatestCount += 1
} Else {
$MacOsOtherCount += 1
@@ -62,9 +70,9 @@ $MacOsResults = $MacOsDevices.GetEnumerator() | Sort-Object -Property Name -Desc
</head><body>"
"<h1>Managed Devices Version Report</h1>"
"<h2>Windows Devices</h2>"
"<p>There are <strong>$WindowsTotal</strong> managed Windows devices:"
"<p>There are <strong>$WindowsTotal</strong> managed Windows devices (that have checked in in the last month):"
"<ul>"
"<li class='good'>$WindowsLatestCount devices are running Windows 11.</li>"
"<li class='good'>$WindowsLatestCount devices are running Windows 11 25H2.</li>"
"<li class='bad'>$WindowsOtherCount devices are running another version of Windows.</li>"
"</ul>"
"</p>"
@@ -73,7 +81,7 @@ $MacOsResults = $MacOsDevices.GetEnumerator() | Sort-Object -Property Name -Desc
"<tr><th>Version</th><th>Number of devices</th></tr>"
ForEach($Result in $WindowsResults) {
If($Result.Name -Like "10.0.2*") {
If($Result.Name -Like "10.0.262*") {
"<tr class='good'><td>$($Result.Name)</td><td class='version'>$($Result.Value)</td></tr>"
} Else {
"<tr class='bad'><td>$($Result.Name)</td><td class='version'>$($Result.Value)</td></tr>"
@@ -83,9 +91,9 @@ ForEach($Result in $WindowsResults) {
"</table>"
"<h2>macOS Devices</h2>"
"<p>There are <strong>$MacOsTotal</strong> managed macOS devices:"
"<p>There are <strong>$MacOsTotal</strong> managed macOS devices (that have checked in in the last month):"
"<ul>"
"<li class='good'>$MacOsLatestCount devices are running macOS Sequoia.</li>"
"<li class='good'>$MacOsLatestCount devices are running macOS Tahoe.</li>"
"<li class='bad'>$MacOsOtherCount devices are running another version of macOS.</li>"
"</ul>"
"</p>"
@@ -94,7 +102,7 @@ ForEach($Result in $WindowsResults) {
"<tr><th>Version</th><th>Number of devices</th></tr>"
ForEach($Result in $MacOsResults) {
If($Result.Name -Like "15.*") {
If($Result.Name -Like "26.*") {
"<tr class='good'><td>$($Result.Name)</td><td class='version'>$($Result.Value)</td></tr>"
} Else {
"<tr class='bad'><td>$($Result.Name)</td><td class='version'>$($Result.Value)</td></tr>"