Get-MgmtGraphManagedDeviceCompliancePolicyState
MgmtGraph: Audits compliance policy states for a managed device
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.DeviceManagement
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$Identity,
[string]$PolicyStateId
)
Process {
try {
$params = @{
'ManagedDeviceId' = $Identity
'ErrorAction' = 'Stop'
}
if ($PolicyStateId) {
$params.Add('DeviceCompliancePolicyStateId', $PolicyStateId)
}
else {
$params.Add('All', $true)
}
$states = Get-MgDeviceManagementManagedDeviceCompliancePolicyState @params
$results = foreach ($s in $states) {
[PSCustomObject]@{
DisplayName = $s.DisplayName
Platform = $s.PlatformType
State = $s.State
SettingCount = $s.SettingCount
Id = $s.Id
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
}
Write-Output ($results | Sort-Object DisplayName)
}
catch {
throw
}
}Specifies the ID of the managed device.
Optional. Specifies the ID of a specific compliance policy state to retrieve. If omitted, all policy states for the device are listed.