PowerShell - Devices with a specific installed KB
Devices with a specific installed KB
PS Script
Script Events:
- Discovers all devices
- Discovers their inventories and extrapolates all installed updates, and then filters the specific one
- Returns all results
Script example:
Script:
#parameters
$serverURI = 'server'
$KB = 'KB4574727'
#script
$creds = Get-Credential
Connect-TSTMGMTServer -Uri $serverURI -Credentials $creds
$Devices = Get-TSTMGMTDevices
$Results = foreach ($D in $Devices) {
$D | Get-TSTMGMTDeviceInventory | Select -ExpandProperty InstalledWindowsUpdates | where {$_.KB -eq $KB} | select -Last 1 @{n='Device';e={$D.DeviceName}},
@{n='Product';e={$D.ProductType}}, KB, Name, DateApplied | sort DateApplied -Descending
}
$Results | ft
TSQL variation
Script Example:
Script:
select distinct DE.DeviceName, WU.KB, WU.Name, Wu.DateApplied,
'ProductType' = CASE
WHEN DE.ProductType = 0 THEN 'TK'
WHEN DE.ProductType = 4 THEN 'SRW'
END
from WindowsUpdates WU
inner join Devices DE on WU.DeviceId = DE.DeviceId
where WU.KB = 'KB4574727'