Skip to content

Get-MgmtGraphEnvironment

MgmtGraph: Lists registered Microsoft Graph cloud environments

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Authentication

[CmdletBinding()]
Param (
    [string]$Name
)

Process {
    try {
        $params = @{
            'ErrorAction' = 'Stop'
        }
        if ($Name) { $params.Add('Name', $Name) }

        $environments = Get-MgEnvironment @params
        
        $results = foreach ($env in $environments) {
            [PSCustomObject]@{
                Name            = $env.Name
                AzureADEndpoint = $env.AzureADEndpoint
                GraphEndpoint   = $env.GraphEndpoint
                Timestamp       = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output ($results | Sort-Object Name)
    }
    catch {
        throw
    }
}

Optional. Filters the list by a specific environment name (wildcards supported).

An interactive directory of PowerShell scripts.