Public/Get-KritTcmDriftReport.ps1
|
function Get-KritTcmDriftReport { <# .SYNOPSIS Read active or filtered TCM drift records. #> [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName)][Alias('Id')][string]$DriftId, [string]$MonitorId, [ValidateSet('active', 'fixed', 'unknownFutureValue')][string]$Status, [int]$Top ) process { $uri = if ($DriftId) { "https://graph.microsoft.com/v1.0/admin/configurationManagement/configurationDrifts/$DriftId" } else { 'https://graph.microsoft.com/v1.0/admin/configurationManagement/configurationDrifts' } $filters = [System.Collections.Generic.List[string]]::new() if ($MonitorId) { $filters.Add("monitorId eq '$MonitorId'") } if ($Status) { $filters.Add("status eq '$Status'") } $query = [System.Collections.Generic.List[string]]::new() if ($filters.Count -gt 0) { $query.Add("`$filter=$([uri]::EscapeDataString(($filters -join ' and ')))") } if ($Top -gt 0) { $query.Add("`$top=$Top") } if ($query.Count -gt 0) { $uri = '{0}?{1}' -f $uri, ($query -join '&') } $response = Invoke-MgGraphRequest -Method GET -Uri $uri -ErrorAction Stop if ($DriftId) { return [pscustomobject]@{ Id = $response.id MonitorId = $response.monitorId ResourceType = $response.resourceType ResourceInstanceIdentifier = $response.resourceInstanceIdentifier BaselineResourceDisplayName = $response.baselineResourceDisplayName Status = $response.status FirstReportedDateTime = $response.firstReportedDateTime DriftedProperties = @($response.driftedProperties) RawResponse = $response } } @($response.value | ForEach-Object { [pscustomobject]@{ Id = $_.id MonitorId = $_.monitorId ResourceType = $_.resourceType BaselineResourceDisplayName = $_.baselineResourceDisplayName Status = $_.status FirstReportedDateTime = $_.firstReportedDateTime DriftedPropertyCount = @($_.driftedProperties).Count RawResponse = $_ } }) } } |