Examples/Get-QualityUpdateReport.ps1
|
[CmdletBinding()] param( [ValidateSet( 'DeviceStatusByPolicy', 'PolicyStatusSummary', 'DeviceErrorsByPolicy' )] [string] $ReportType = 'PolicyStatusSummary', [guid] $PolicyId, [string] $Filter, [string[]] $Select, [Parameter(Mandatory)] [guid] $TenantId, [ValidateSet('Global', 'USGov', 'USGovDoD')] [string] $Environment = 'Global' ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $moduleManifest = Join-Path $PSScriptRoot '..\MicrosoftGraphWindowsUpdates.psd1' Import-Module $moduleManifest -Force $requiredScope = 'DeviceManagementConfiguration.ReadWrite.All' $tenantIdValue = $TenantId.ToString() $context = Get-MgContext if (-not $context) { $connectParameters = @{ Scopes = $requiredScope TenantId = $tenantIdValue Environment = $Environment NoWelcome = $true } Connect-MgGraph @connectParameters $context = Get-MgContext } if (-not $context) { throw 'Microsoft Graph did not return an active context after authentication.' } if (-not $context.Environment) { throw 'The active Microsoft Graph context does not identify its environment.' } if ($context.Environment -ne $Environment) { throw ( "The active Microsoft Graph environment '$($context.Environment)' does not match " + "the requested environment '$Environment'. Disconnect and authenticate again." ) } if (-not $context.TenantId) { throw 'The active Microsoft Graph context does not identify its tenant.' } if ($context.TenantId -ne $tenantIdValue) { throw ( "The active Microsoft Graph tenant '$($context.TenantId)' does not match " + "the requested tenant '$tenantIdValue'. Disconnect and authenticate again." ) } if ($context.AuthType -ne 'AppOnly' -and $context.Scopes -and $requiredScope -notin $context.Scopes) { throw ( "The active Microsoft Graph session is missing '$requiredScope'. " + 'Reconnect once with that scope before running this script.' ) } $reportParameters = @{ ReportType = $ReportType } foreach ($parameterName in 'PolicyId', 'Filter', 'Select') { if ($PSBoundParameters.ContainsKey($parameterName)) { $reportParameters[$parameterName] = $PSBoundParameters[$parameterName] } } Get-MgWindowsUpdateQualityReport @reportParameters |