Public/UpdatePolicy.ps1

function Get-MgWindowsUpdatePolicyBeta {
    <#
    .SYNOPSIS
    Gets legacy updatePolicy resources from the beta API.
    .DESCRIPTION
    Gets legacy updatePolicy resources from the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.Read.All or WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER All
    Follows Microsoft Graph pagination links until all result pages are returned.
    .PARAMETER Count
    Requests the OData count annotation.
    .PARAMETER Expand
    Specifies related resources to include through OData $expand.
    .PARAMETER Filter
    Specifies an OData $filter expression.
    .PARAMETER OrderBy
    Specifies an OData $orderby expression.
    .PARAMETER Query
    Specifies additional OData query parameters as key-value pairs.
    .PARAMETER Select
    Specifies properties to include through OData $select.
    .PARAMETER Skip
    Specifies the number of items to skip.
    .PARAMETER Top
    Specifies the maximum number of items requested from Microsoft Graph.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> Get-MgWindowsUpdatePolicyBeta `
        -Select id `
        -All
 
    Gets legacy updatePolicy resources from the beta API. The example requests useful identity fields and follows all pages when the endpoint supports pagination.
    #>

    [CmdletBinding()]
    param(
        [string] $UpdatePolicyId,
        [string] $Filter,
        [string[]] $Select,
        [string[]] $Expand,
        [string[]] $OrderBy,
        [ValidateRange(1, 999)]
        [int] $Top,
        [ValidateRange(0, [int]::MaxValue)]
        [int] $Skip,
        [switch] $Count,
        [switch] $All,
        [hashtable] $Query
    )

    $path = if ($UpdatePolicyId) {
        "updatePolicies/$UpdatePolicyId"
    }
    else {
        'updatePolicies'
    }
    $odata = Get-MgWindowsUpdatesQuery -BoundParameters $PSBoundParameters
    Invoke-MgWindowsUpdatesRequest -Method GET -Path $path -Query $odata -All:$All
}

function New-MgWindowsUpdatePolicyBeta {
    <#
    .SYNOPSIS
    Creates a legacy updatePolicy resource using the beta API.
    .DESCRIPTION
    Creates a legacy updatePolicy resource using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER Body
    Specifies the Microsoft Graph request body.
    .EXAMPLE
    PS> $body = @{
        '@odata.type' = '#microsoft.graph.windowsUpdates.updatePolicy'
        audience = @{
            id = 'd39ad1ce-0123-4567-89ab-cdef01234567'
        }
        complianceChangeRules = @(
            @{
                '@odata.type' = (
                    '#microsoft.graph.windowsUpdates.contentApprovalRule'
                )
                contentFilter = @{
                    '@odata.type' = (
                        '#microsoft.graph.windowsUpdates.driverUpdateFilter'
                    )
                }
                durationBeforeDeploymentStart = 'P7D'
            }
        )
    }
    New-MgWindowsUpdatePolicyBeta `
        -Body $body `
        -WhatIf
 
    Adapts the documented driver updatePolicy example and previews policy creation.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [hashtable] $Body
    )

    if ($PSCmdlet.ShouldProcess('Windows update policies', 'Create beta updatePolicy')) {
        Invoke-MgWindowsUpdatesRequest -Method POST -Path 'updatePolicies' -Body $Body
    }
}

function Set-MgWindowsUpdatePolicyBeta {
    <#
    .SYNOPSIS
    Updates a legacy updatePolicy resource using the beta API.
    .DESCRIPTION
    Updates a legacy updatePolicy resource using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER Body
    Specifies the Microsoft Graph request body.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $body = @{
        complianceChangeRules = @(
            @{
                '@odata.type' = (
                    '#microsoft.graph.windowsUpdates.contentApprovalRule'
                )
                contentFilter = @{
                    '@odata.type' = (
                        '#microsoft.graph.windowsUpdates.driverUpdateFilter'
                    )
                }
            }
        )
        deploymentSettings = @{
            '@odata.type' = (
                '#microsoft.graph.windowsUpdates.deploymentSettings'
            )
            contentApplicability = @{
                '@odata.type' = (
                    '#microsoft.graph.windowsUpdates.contentApplicabilitySettings'
                )
                offerWhileRecommendedBy = @('microsoft')
            }
        }
    }
    $updatePolicyId = '9011c330-1234-5678-9abc-def012345678'
    Set-MgWindowsUpdatePolicyBeta `
        -Body $body `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
 
    Adapts the documented updatePolicy example that automatically approves
    Microsoft-recommended driver content.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [hashtable] $Body
    )

    if ($PSCmdlet.ShouldProcess($UpdatePolicyId, 'Update beta updatePolicy')) {
        Invoke-MgWindowsUpdatesRequest -Method PATCH `
            -Path "updatePolicies/$UpdatePolicyId" `
            -Body $Body
    }
}

function Remove-MgWindowsUpdatePolicyBeta {
    <#
    .SYNOPSIS
    Deletes a legacy updatePolicy resource using the beta API.
    .DESCRIPTION
    Deletes a legacy updatePolicy resource using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $updatePolicyId = '<update-policy-id>'
    Remove-MgWindowsUpdatePolicyBeta `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
    Deletes a legacy updatePolicy resource using the beta API. The example uses -WhatIf so the target and payload can be reviewed before making the change.
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId
    )

    if ($PSCmdlet.ShouldProcess($UpdatePolicyId, 'Delete beta updatePolicy')) {
        Invoke-MgWindowsUpdatesRequest -Method DELETE -Path "updatePolicies/$UpdatePolicyId"
    }
}

function Get-MgWindowsUpdateComplianceChangeBeta {
    <#
    .SYNOPSIS
    Gets compliance changes for a legacy updatePolicy using the beta API.
    .DESCRIPTION
    Gets compliance changes for a legacy updatePolicy using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.Read.All or WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER All
    Follows Microsoft Graph pagination links until all result pages are returned.
    .PARAMETER ComplianceChangeId
    Specifies the Microsoft Graph identifier of the compliance change.
    .PARAMETER ContentApprovalOnly
    Specifies the content approval only.
    .PARAMETER Expand
    Specifies related resources to include through OData $expand.
    .PARAMETER Filter
    Specifies an OData $filter expression.
    .PARAMETER OrderBy
    Specifies an OData $orderby expression.
    .PARAMETER Query
    Specifies additional OData query parameters as key-value pairs.
    .PARAMETER Select
    Specifies properties to include through OData $select.
    .PARAMETER Top
    Specifies the maximum number of items requested from Microsoft Graph.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $updatePolicyId = '<update-policy-id>'
    Get-MgWindowsUpdateComplianceChangeBeta `
        -UpdatePolicyId $updatePolicyId `
        -Select id `
        -All
 
    Gets compliance changes for a legacy updatePolicy using the beta API. The example requests useful identity fields and follows all pages when the endpoint supports pagination.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [string] $ComplianceChangeId,

        [switch] $ContentApprovalOnly,

        [string] $Filter,
        [string[]] $Select,
        [string[]] $Expand,
        [string[]] $OrderBy,
        [ValidateRange(1, 999)]
        [int] $Top,
        [switch] $All,
        [hashtable] $Query
    )

    $path = if ($ComplianceChangeId) {
        "updatePolicies/$UpdatePolicyId/complianceChanges/$ComplianceChangeId"
    }
    elseif ($ContentApprovalOnly) {
        "updatePolicies/$UpdatePolicyId/complianceChanges/" +
            'microsoft.graph.windowsUpdates.contentApproval'
    }
    else {
        "updatePolicies/$UpdatePolicyId/complianceChanges"
    }
    $odata = Get-MgWindowsUpdatesQuery -BoundParameters $PSBoundParameters
    Invoke-MgWindowsUpdatesRequest -Method GET -Path $path -Query $odata -All:$All
}

function New-MgWindowsUpdateContentApprovalBeta {
    <#
    .SYNOPSIS
    Creates a contentApproval compliance change using the beta API.
    .DESCRIPTION
    Creates a contentApproval compliance change using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER Body
    Specifies the Microsoft Graph request body.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $body = @{
        '@odata.type' = '#microsoft.graph.windowsUpdates.contentApproval'
        content = @{
            '@odata.type' = '#microsoft.graph.windowsUpdates.catalogContent'
            catalogEntry = @{
                '@odata.type' = (
                    '#microsoft.graph.windowsUpdates.driverUpdateCatalogEntry'
                )
                id = (
                    '5d6dede684ba5c4a731d62d9c9c2a99d' +
                    'b12c5e6015e9f8ad00f3e9387c7f399c'
                )
            }
        }
        deploymentSettings = @{
            '@odata.type' = (
                '#microsoft.graph.windowsUpdates.deploymentSettings'
            )
            schedule = @{
                startDateTime = '2026-11-15T01:00:00Z'
            }
        }
    }
    $updatePolicyId = '9011c330-1234-5678-9abc-def012345678'
    New-MgWindowsUpdateContentApprovalBeta `
        -Body $body `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
 
    Adapts the documented driver contentApproval request and previews approval.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [hashtable] $Body
    )

    $requestBody = @{} + $Body
    if (-not $requestBody.ContainsKey('@odata.type')) {
        $requestBody['@odata.type'] = '#microsoft.graph.windowsUpdates.contentApproval'
    }
    if ($PSCmdlet.ShouldProcess($UpdatePolicyId, 'Create beta content approval')) {
        Invoke-MgWindowsUpdatesRequest -Method POST `
            -Path "updatePolicies/$UpdatePolicyId/complianceChanges" `
            -Body $requestBody
    }
}

function Get-MgWindowsUpdateContentApprovalBeta {
    <#
    .SYNOPSIS
    Gets content approval compliance changes using the beta API.
    .DESCRIPTION
    Gets content approval compliance changes using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.Read.All or WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER All
    Follows Microsoft Graph pagination links until all result pages are returned.
    .PARAMETER ContentApprovalId
    Specifies the Microsoft Graph identifier of the content approval.
    .PARAMETER Expand
    Specifies related resources to include through OData $expand.
    .PARAMETER Filter
    Specifies an OData $filter expression.
    .PARAMETER OrderBy
    Specifies an OData $orderby expression.
    .PARAMETER Query
    Specifies additional OData query parameters as key-value pairs.
    .PARAMETER Select
    Specifies properties to include through OData $select.
    .PARAMETER Top
    Specifies the maximum number of items requested from Microsoft Graph.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $updatePolicyId = '<update-policy-id>'
    Get-MgWindowsUpdateContentApprovalBeta `
        -UpdatePolicyId $updatePolicyId `
        -Select id `
        -All
 
    Gets content approval compliance changes using the beta API. The example requests useful identity fields and follows all pages when the endpoint supports pagination.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [string] $ContentApprovalId,

        [string] $Filter,
        [string[]] $Select,
        [string[]] $Expand,
        [string[]] $OrderBy,
        [ValidateRange(1, 999)]
        [int] $Top,
        [switch] $All,
        [hashtable] $Query
    )

    $parameters = @{}
    foreach ($key in $PSBoundParameters.Keys) {
        $parameters[$key] = $PSBoundParameters[$key]
    }
    $parameters.Remove('ContentApprovalId')
    $parameters.ContentApprovalOnly = $true
    if ($ContentApprovalId) {
        $parameters.ComplianceChangeId = $ContentApprovalId
    }
    Get-MgWindowsUpdateComplianceChangeBeta @parameters
}

function Set-MgWindowsUpdateComplianceChangeBeta {
    <#
    .SYNOPSIS
    Updates a compliance change using the beta API.
    .DESCRIPTION
    Updates a compliance change using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER Body
    Specifies the Microsoft Graph request body.
    .PARAMETER ComplianceChangeId
    Specifies the Microsoft Graph identifier of the compliance change.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $body = @{
        deploymentSettings = @{
            '@odata.type' = (
                '#microsoft.graph.windowsUpdates.deploymentSettings'
            )
            schedule = @{
                startDateTime = '2026-11-22T01:00:00Z'
            }
        }
    }
    $complianceChangeId = 'c03911a7-9876-5432-10ab-cdef98765432'
    $updatePolicyId = '9011c330-1234-5678-9abc-def012345678'
    Set-MgWindowsUpdateComplianceChangeBeta `
        -Body $body `
        -ComplianceChangeId $complianceChangeId `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
 
    Uses the documented deploymentSettings shape to preview rescheduling a
    compliance change.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [Parameter(Mandatory)]
        [string] $ComplianceChangeId,

        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [hashtable] $Body
    )

    if ($PSCmdlet.ShouldProcess($ComplianceChangeId, 'Update beta compliance change')) {
        Invoke-MgWindowsUpdatesRequest -Method PATCH `
            -Path "updatePolicies/$UpdatePolicyId/complianceChanges/$ComplianceChangeId" `
            -Body $Body
    }
}

function Set-MgWindowsUpdateContentApprovalBeta {
    <#
    .SYNOPSIS
    Updates a content approval compliance change using the beta API.
    .DESCRIPTION
    Updates a content approval compliance change using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER Body
    Specifies the Microsoft Graph request body.
    .PARAMETER ContentApprovalId
    Specifies the Microsoft Graph identifier of the content approval.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $body = @{
        deploymentSettings = @{
            '@odata.type' = (
                '#microsoft.graph.windowsUpdates.deploymentSettings'
            )
            schedule = @{
                startDateTime = '2026-11-22T01:00:00Z'
            }
        }
    }
    $contentApprovalId = 'c03911a7-9876-5432-10ab-cdef98765432'
    $updatePolicyId = '9011c330-1234-5678-9abc-def012345678'
    Set-MgWindowsUpdateContentApprovalBeta `
        -Body $body `
        -ContentApprovalId $contentApprovalId `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
 
    Uses the documented deploymentSettings shape to preview rescheduling approval.
    #>

    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [Parameter(Mandatory)]
        [string] $ContentApprovalId,

        [Parameter(Mandatory)]
        [ValidateNotNull()]
        [hashtable] $Body
    )

    if ($PSCmdlet.ShouldProcess($ContentApprovalId, 'Update beta content approval')) {
        Set-MgWindowsUpdateComplianceChangeBeta `
            -UpdatePolicyId $UpdatePolicyId `
            -ComplianceChangeId $ContentApprovalId `
            -Body $Body `
            -Confirm:$false
    }
}

function Remove-MgWindowsUpdateComplianceChangeBeta {
    <#
    .SYNOPSIS
    Deletes a compliance change using the beta API.
    .DESCRIPTION
    Deletes a compliance change using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER ComplianceChangeId
    Specifies the Microsoft Graph identifier of the compliance change.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $complianceChangeId = '<compliance-change-id>'
    $updatePolicyId = '<update-policy-id>'
    Remove-MgWindowsUpdateComplianceChangeBeta `
        -ComplianceChangeId $complianceChangeId `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
    Deletes a compliance change using the beta API. The example uses -WhatIf so the target and payload can be reviewed before making the change.
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [Parameter(Mandatory)]
        [string] $ComplianceChangeId
    )

    if ($PSCmdlet.ShouldProcess($ComplianceChangeId, 'Delete beta compliance change')) {
        Invoke-MgWindowsUpdatesRequest -Method DELETE `
            -Path "updatePolicies/$UpdatePolicyId/complianceChanges/$ComplianceChangeId"
    }
}

function Remove-MgWindowsUpdateContentApprovalBeta {
    <#
    .SYNOPSIS
    Deletes a content approval compliance change using the beta API.
    .DESCRIPTION
    Deletes a content approval compliance change using the beta API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requires WindowsUpdates.ReadWrite.All in the active Microsoft Graph context.
    .PARAMETER ContentApprovalId
    Specifies the Microsoft Graph identifier of the content approval.
    .PARAMETER UpdatePolicyId
    Specifies the Microsoft Graph identifier of the update policy.
    .EXAMPLE
    PS> $contentApprovalId = '<content-approval-id>'
    $updatePolicyId = '<update-policy-id>'
    Remove-MgWindowsUpdateContentApprovalBeta `
        -ContentApprovalId $contentApprovalId `
        -UpdatePolicyId $updatePolicyId `
        -WhatIf
    Deletes a content approval compliance change using the beta API. The example uses -WhatIf so the target and payload can be reviewed before making the change.
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
    param(
        [Parameter(Mandatory)]
        [string] $UpdatePolicyId,

        [Parameter(Mandatory)]
        [string] $ContentApprovalId
    )

    if ($PSCmdlet.ShouldProcess($ContentApprovalId, 'Delete beta content approval')) {
        Remove-MgWindowsUpdateComplianceChangeBeta `
            -UpdatePolicyId $UpdatePolicyId `
            -ComplianceChangeId $ContentApprovalId `
            -Confirm:$false
    }
}