Public/Connection.ps1

function Connect-MgWindowsUpdatesBeta {
    <#
    .SYNOPSIS
    Connects to Microsoft Graph for the beta Windows updates API.
    .DESCRIPTION
    Connects to Microsoft Graph for the beta Windows updates API. This command uses the Microsoft Graph beta endpoint; beta behavior and schemas can change without notice. Requests the least-privilege delegated scopes selected by the command parameters.
    .PARAMETER Environment
    Specifies the Microsoft Graph cloud environment.
    .PARAMETER IncludeIntuneReports
    Also requests the Intune report scope required by stable quality update reports.
    .PARAMETER NoWelcome
    Specifies the no welcome.
    .PARAMETER ReadWrite
    Specifies the read write.
    .PARAMETER TenantId
    Specifies the Microsoft Graph identifier of the tenant.
    .EXAMPLE
    PS> Connect-MgWindowsUpdatesBeta -ReadWrite -IncludeIntuneReports
 
    Connects once with the Windows Updates read/write scope and the additional Intune report-export scope. Subsequent module commands reuse this process-scoped Graph context.
    #>

    [CmdletBinding()]
    param(
        [switch] $ReadWrite,

        [switch] $IncludeIntuneReports,

        [string] $TenantId,

        [ValidateSet('Global', 'USGov', 'USGovDoD')]
        [string] $Environment = 'Global',

        [switch] $NoWelcome
    )

    $scopes = @(
        if ($ReadWrite) {
            'WindowsUpdates.ReadWrite.All'
        }
        else {
            'WindowsUpdates.Read.All'
        }
    )
    if ($IncludeIntuneReports) {
        $scopes += 'DeviceManagementConfiguration.ReadWrite.All'
    }

    $arguments = @{
        Scopes = $scopes
        Environment = $Environment
    }
    if ($TenantId) {
        $arguments.TenantId = $TenantId
    }
    if ($NoWelcome) {
        $arguments.NoWelcome = $true
    }

    Connect-MgGraph @arguments
}