Connect-Maester
SYNOPSIS
Section titled “SYNOPSIS”Helper method to connect to Microsoft Graph using Connect-MgGraph with the required permission scopes as well as other services such as Azure, Exchange Online, and GitHub.
SYNTAX
Section titled “SYNTAX”Connect-Maester [-SendMail] [-SendTeamsMessage] [-Privileged] [-IncludePreview] [-UseDeviceCode] [[-Environment] <String>] [[-AzureEnvironment] <String>] [[-ExchangeEnvironmentName] <String>] [[-TeamsEnvironmentName] <String>] [[-Service] <String[]>] [[-TenantId] <String>] [[-GraphClientId] <String>] [[-ClientTimeout] <Double>] [[-SharePointClientId] <String>] [[-SharePointAdminUrl] <String>] [[-SharePointCertificateThumbprint] <String>] [[-GitHubOrganization] <String>] [[-ActiveDirectoryForest] <Object>] [[-ActiveDirectoryDomain] <Object>] [[-ActiveDirectoryServer] <Object>] [[-ActiveDirectoryCredential] <PSCredential>] [[-ActiveDirectoryAuthMode] <String>] [[-ActiveDirectoryTlsMode] <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]DESCRIPTION
Section titled “DESCRIPTION”Use this cmdlet to connect to Microsoft Graph and the Microsoft 365 services that Maester can assess. By default, it connects to Microsoft Graph. Use -Service All to connect to Microsoft 365 services, including Microsoft Graph, Azure, Exchange Online, Security & Compliance, Microsoft Teams, SharePoint Online, and Dataverse.
Non-Microsoft 365 services such as Active Directory and GitHub are not included in -Service All and must be explicitly specified.
When it finishes, Connect-Maester shows a summary table with the status of each service it tried (Connected, Skipped, Failed or Not installed) and a short detail. Use -Verbose to see the step-by-step messages for each connection.
This command is completely optional if you are already connected to Microsoft Graph and other services using Connect-MgGraph with the required scopes.
Connect-MgGraph -Scopes (Get-MtGraphScope)EXAMPLES
Section titled “EXAMPLES”EXAMPLE 1
Section titled “EXAMPLE 1”Connect-MaesterConnects only to Microsoft Graph by default.
EXAMPLE 2
Section titled “EXAMPLE 2”Connect-Maester -Service Graph,TeamsConnects to Microsoft Graph and Microsoft Teams.
EXAMPLE 3
Section titled “EXAMPLE 3”Connect-Maester -Service Graph,GitHub -GitHubOrganization 'mycompany'Connects to Microsoft Graph and GitHub. GitHub sign-in is handled by Connect-MtGitHub using the Maester GitHub App device flow by default, including guided organization app install/approval when required. Automation can still use MAESTER_GITHUB_TOKEN or GH_TOKEN.
EXAMPLE 4
Section titled “EXAMPLE 4”Connect-Maester -Service ActiveDirectoryValidates connectivity to the current Active Directory domain. Active Directory must be explicitly selected and is not included in -Service All.
EXAMPLE 5
Section titled “EXAMPLE 5”Connect-Maester -Service Azure,GraphConnects to Microsoft Graph and Azure.
EXAMPLE 6
Section titled “EXAMPLE 6”Connect-Maester -Service Dataverse,GraphConnects to Microsoft Graph and the Dataverse API for Copilot Studio security tests. The Dataverse connection uses the Az.Accounts module. The Copilot Studio environment is auto-discovered via the Global Discovery Service, or can be explicitly set with DataverseEnvironmentUrl in maester-config.json.
EXAMPLE 7
Section titled “EXAMPLE 7”Connect-Maester -UseDeviceCodeConnects to Microsoft Graph and Azure using the device code flow. This will open a browser window to prompt for authentication.
EXAMPLE 8
Section titled “EXAMPLE 8”Connect-Maester -SendMailConnects to Microsoft Graph with the Mail.Send scope.
EXAMPLE 9
Section titled “EXAMPLE 9”Connect-Maester -SendTeamsMessageConnects to Microsoft Graph with the ChannelMessage.Send scope.
EXAMPLE 10
Section titled “EXAMPLE 10”Connect-Maester -PrivilegedConnects to Microsoft Graph with additional privileged scopes such as RoleEligibilitySchedule.ReadWrite.Directory that are required for querying Global Administrator roles in Privileged Identity Management.
EXAMPLE 11
Section titled “EXAMPLE 11”Connect-Maester -IncludePreviewConnects to Microsoft Graph with the additional scopes required by preview tests.
EXAMPLE 12
Section titled “EXAMPLE 12”Connect-Maester -Environment USGov -AzureEnvironment AzureUSGovernment -ExchangeEnvironmentName O365USGovGCCHighConnects to US Government environments for Microsoft Graph, Azure, and Exchange Online.
EXAMPLE 13
Section titled “EXAMPLE 13”Connect-Maester -Environment USGovDoD -AzureEnvironment AzureUSGovernment -ExchangeEnvironmentName O365USGovDoDConnects to US Department of Defense (DoD) environments for Microsoft Graph, Azure, and Exchange Online.
EXAMPLE 14
Section titled “EXAMPLE 14”Connect-Maester -Environment China -AzureEnvironment AzureChinaCloud -ExchangeEnvironmentName O365ChinaConnects to China environments for Microsoft Graph, Azure, and Exchange Online.
EXAMPLE 15
Section titled “EXAMPLE 15”Connect-Maester -GraphClientId 'f45ec3ad-32f0-4c06-8b69-47682afe0216'Connects using a custom application with client ID f45ec3ad-32f0-4c06-8b69-47682afe0216
EXAMPLE 16
Section titled “EXAMPLE 16”Connect-Maester -ClientTimeout 900Connects to Microsoft Graph with an HTTP client timeout of 900 seconds. This can be useful for long-running tests in large tenants.
EXAMPLE 17
Section titled “EXAMPLE 17”'Connects to Microsoft Graph and SharePoint Online using the specified PnP app registration. The SharePoint admin URL is auto-discovered from the tenant’s initial domain via the Graph API. Optionally, specify -SharePointAdminUrl to override the auto-discovered URL (e.g. for custom domain or government cloud tenants).
EXAMPLE 18
Section titled “EXAMPLE 18”Connect-Maester -Service SharePointOnline -SharePointClientId 'f45ec3ad-32f0-4c06-8b69-47682afe0216' -SharePointAdminUrl 'https://contoso-admin.sharepoint.com'Connects to SharePoint Online using the specified client ID and admin URL.
PARAMETERS
Section titled “PARAMETERS”-SendMail
Section titled “-SendMail”If specified, the cmdlet will include the scope to send email (Mail.Send).
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-SendTeamsMessage
Section titled “-SendTeamsMessage”If specified, the cmdlet will include the scope to send a channel message in Teams (ChannelMessage.Send).
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-Privileged
Section titled “-Privileged”If specified, the cmdlet will include the scopes for read write API endpoints. This is currently required for querying Global Administrator roles in PIM.
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-IncludePreview
Section titled “-IncludePreview”If specified, the cmdlet will include scopes required by preview tests.
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-UseDeviceCode
Section titled “-UseDeviceCode”If specified, the cmdlet will use the device code flow to authenticate to Graph and Azure. This will open a browser window to prompt for authentication and is useful for non-interactive sessions and on Windows when SSO is not desired.
Type: SwitchParameterParameter Sets: (All)Aliases:
Required: FalsePosition: NamedDefault value: FalseAccept pipeline input: FalseAccept wildcard characters: False-Environment
Section titled “-Environment”The environment to connect to. Default is Global. Supported values include China, Germany, Global, USGov, USGovDoD.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 1Default value: GlobalAccept pipeline input: FalseAccept wildcard characters: False-AzureEnvironment
Section titled “-AzureEnvironment”The Azure environment to connect to. Default is AzureCloud. Supported values include AzureChinaCloud, AzureCloud, AzureUSGovernment.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 2Default value: AzureCloudAccept pipeline input: FalseAccept wildcard characters: False-ExchangeEnvironmentName
Section titled “-ExchangeEnvironmentName”The Exchange environment to connect to. Default is O365Default. Supported values include O365China, O365Default, O365GermanyCloud, O365USGovDoD, O365USGovGCCHigh.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 3Default value: O365DefaultAccept pipeline input: FalseAccept wildcard characters: False-TeamsEnvironmentName
Section titled “-TeamsEnvironmentName”The Teams environment to connect to. Default is O365Default.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 4Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-Service
Section titled “-Service”The services to connect to such as Active Directory, Azure, Dataverse (for Copilot Studio tests), EXO, GitHub, and SharePoint Online. Default is Graph. Active Directory and GitHub are not included in All and must be explicitly specified.
Type: String[]Parameter Sets: (All)Aliases:
Required: FalsePosition: 5Default value: GraphAccept pipeline input: FalseAccept wildcard characters: False-TenantId
Section titled “-TenantId”The Tenant ID to connect to, if not specified the sign-in user’s default tenant is used.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 6Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-GraphClientId
Section titled “-GraphClientId”The Client ID of the app to connect to for Graph. If not specified, the default Graph PowerShell CLI enterprise app will be used. Reference on how to create an enterprise app: https://learn.microsoft.com/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#use-delegated-access-with-a-custom-application-for-microsoft-graph-powershell
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 7Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ClientTimeout
Section titled “-ClientTimeout”The Microsoft Graph HTTP client timeout in seconds. When omitted, the Microsoft Graph PowerShell SDK default is used.
Type: DoubleParameter Sets: (All)Aliases:
Required: FalsePosition: 8Default value: 0Accept pipeline input: FalseAccept wildcard characters: False-SharePointClientId
Section titled “-SharePointClientId”The Client ID of the PnP Entra ID app for SharePoint Online. Required when Service includes SharePointOnline. Use Register-PnPEntraIDAppForInteractiveLogin to create a dedicated app, or reuse an existing Maester app registration by adding an http://localhost redirect URI and AllSites.FullControl delegated SharePoint permission.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 9Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-SharePointAdminUrl
Section titled “-SharePointAdminUrl”The SharePoint admin center URL to connect to when using the SharePointOnline service (e.g. https://contoso-admin.sharepoint.com). If not specified, the URL is auto-discovered from the tenant’s initial domain via the Microsoft Graph API.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 10Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-SharePointCertificateThumbprint
Section titled “-SharePointCertificateThumbprint”The certificate thumbprint for app-only authentication to SharePoint Online. Use together with -SharePointClientId and -TenantId for non-interactive/automation scenarios. The certificate must be installed in the current user’s certificate store.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 11Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-GitHubOrganization
Section titled “-GitHubOrganization”The GitHub organization login name to connect to when Service includes GitHub.
Type: StringParameter Sets: (All)Aliases:
Required: FalsePosition: 12Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ActiveDirectoryForest
Section titled “-ActiveDirectoryForest”The Active Directory forest DNS name to discover when Service includes ActiveDirectory.
Type: ObjectParameter Sets: (All)Aliases:
Required: FalsePosition: 13Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ActiveDirectoryDomain
Section titled “-ActiveDirectoryDomain”The Active Directory domain DNS name to discover when Service includes ActiveDirectory.
Type: ObjectParameter Sets: (All)Aliases:
Required: FalsePosition: 14Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ActiveDirectoryServer
Section titled “-ActiveDirectoryServer”The Active Directory domain controller to connect to when Service includes ActiveDirectory.
Type: ObjectParameter Sets: (All)Aliases:
Required: FalsePosition: 15Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ActiveDirectoryCredential
Section titled “-ActiveDirectoryCredential”The credential used for the Active Directory LDAP connection.
Type: PSCredentialParameter Sets: (All)Aliases:
Required: FalsePosition: 16Default value: NoneAccept pipeline input: FalseAccept wildcard characters: False-ActiveDirectoryAuthMode
Section titled “-ActiveDirectoryAuthMode”The authentication mode used for the Active Directory LDAP connection.
Type: StringParameter Sets: (All)Aliases: AuthMode
Required: FalsePosition: 17Default value: NegotiateAccept pipeline input: FalseAccept wildcard characters: False-ActiveDirectoryTlsMode
Section titled “-ActiveDirectoryTlsMode”The TLS mode used for the Active Directory LDAP connection. Auto tries LDAPS before StartTLS.
Type: StringParameter Sets: (All)Aliases: TlsMode
Required: FalsePosition: 18Default value: AutoAccept pipeline input: FalseAccept wildcard characters: False-ProgressAction
Section titled “-ProgressAction”Determines how PowerShell responds to progress updates generated by a script, cmdlet, or provider, such as the progress bars generated by Write-Progress.
Type: ActionPreferenceParameter Sets: (All)Aliases: proga
Required: FalsePosition: NamedDefault value: NoneAccept pipeline input: FalseAccept wildcard characters: FalseCommonParameters
Section titled “CommonParameters”This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.