test-CloudDLPresentGraph.ps1

<#
    .SYNOPSIS
 
    This function loops until we detect that the cloud DL is no longer present.
     
    .DESCRIPTION
 
    This function loops until we detect that the cloud DL is no longer present.
 
    .PARAMETER groupSMTPAddress
 
    The SMTP Address of the group.
 
    .OUTPUTS
 
    None
 
    .EXAMPLE
 
    test-CloudDLPresent -groupSMTPAddress SMTPAddress
 
    #>

    Function test-CloudDLPresentGraph
     {
        [cmdletbinding()]

        Param
        (
            [Parameter(Mandatory = $true)]
            [string]$groupSMTPAddress,
            [Parameter(Mandatory = $true)]
            [string]$msGraphURL
        )

        #Output all parameters bound or unbound and their associated values.

        write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)

        #Declare function variables.

        $functionRecipient = $NULL
        $functionURIType = "OnPremisesSyncBehavior"
        $functionURI = ""

        #Start function processing.

        Out-LogFile -string "********************************************************************************"
        Out-LogFile -string "BEGIN test-ClouDLPresentGraph"
        Out-LogFile -string "********************************************************************************"

        $functionURI = get-graphURI -msGraphURL $msGraphURL -externalDirectoryObjectID $office365DLConfiguration.externalDirectoryObjectID -uriType $functionURIType -errorAction STOP

        try {
            $functionRecipient = Invoke-MgGraphRequest -Method Get -Uri $functionURI
        }
        catch {
            out-logfile -string "Unable to obtain the Exchange Online distribution list."
            out-logfile -string $_ -isError:$TRUE
        } 

        if ($functionRecipient.onPremisesSyncEnabled -eq $true)
        {
            do 
            {
                start-sleepProgress -sleepString "Group still directory synchronized in EntraID - sleep for 30 seconds - try again." -sleepSeconds 30
                $functionRecipient = Invoke-MgGraphRequest -Method Get -Uri $functionURI
            } while ($functionRecipient.onPremisesSyncEnabled -eq $true)
        }
        else 
        {
            out-logfile -string "Bypass do while - group is already cloud only."
        }
        

        Out-LogFile -string "END test-ClouDLPresentGraph"
        Out-LogFile -string "********************************************************************************"
    }