Skip to main content
Version: 2.1.1-preview

Connect-M365Advisor

SYNOPSIS​

Helper method to connect to Microsoft Graph using Connect-MgGraph with the required permission scopes as well as other services such as Azure and Exchange Online.

SYNTAX​

Connect-M365Advisor [-SendMail] [-SendTeamsMessage] [-Privileged] [-UseDeviceCode] [[-Environment] <String>]
[[-AzureEnvironment] <String>] [[-ExchangeEnvironmentName] <String>] [[-TeamsEnvironmentName] <String>]
[[-Service] <String[]>] [[-TenantId] <String>] [[-GraphClientId] <String>] [[-SharePointClientId] <String>]
[[-SharePointAdminUrl] <String>] [[-SharePointCertificateThumbprint] <String>]
[-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION​

Use this cmdlet to connect to Microsoft Graph and the Microsoft 365 services that M365Advisor can assess. It attempts to connect to all services by default: Microsoft Graph, Azure, Exchange Online, and Microsoft Teams.

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​

EXAMPLE 1​

Connect-M365Advisor

Connects to all Microsoft services that M365Advisor is able to assess: Microsoft Graph, Azure, Exchange Online, Exchange Online Security & Compliance, and Microsoft Teams.

EXAMPLE 2​

Connect-M365Advisor -Service Graph,Teams

Connects to Microsoft Graph and Microsoft Teams.

EXAMPLE 3​

Connect-M365Advisor -Service Azure,Graph

Connects to Microsoft Graph and Azure.

EXAMPLE 4​

Connect-M365Advisor -Service Dataverse,Graph

Connects 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 m365advisor-config.json.

EXAMPLE 5​

Connect-M365Advisor -UseDeviceCode

Connects to Microsoft Graph and Azure using the device code flow. This will open a browser window to prompt for authentication.

EXAMPLE 6​

Connect-M365Advisor -SendMail

Connects to Microsoft Graph with the Mail.Send scope.

EXAMPLE 7​

Connect-M365Advisor -SendTeamsMessage

Connects to Microsoft Graph with the ChannelMessage.Send scope.

EXAMPLE 8​

Connect-M365Advisor -Privileged

Connects to Microsoft Graph with additional privileged scopes such as RoleEligibilitySchedule.ReadWrite.Directory that are required for querying global admin roles in Privileged Identity Management.

EXAMPLE 9​

Connect-M365Advisor -Environment USGov -AzureEnvironment AzureUSGovernment -ExchangeEnvironmentName O365USGovGCCHigh

Connects to US Government environments for Microsoft Graph, Azure, and Exchange Online.

EXAMPLE 10​

Connect-M365Advisor -Environment USGovDoD -AzureEnvironment AzureUSGovernment -ExchangeEnvironmentName O365USGovDoD

Connects to US Department of Defense (DoD) environments for Microsoft Graph, Azure, and Exchange Online.

EXAMPLE 11​

Connect-M365Advisor -Environment China -AzureEnvironment AzureChinaCloud -ExchangeEnvironmentName O365China

Connects to China environments for Microsoft Graph, Azure, and Exchange Online.

EXAMPLE 12​

Connect-M365Advisor -GraphClientId 'f45ec3ad-32f0-4c06-8b69-47682afe0216'

Connects using a custom application with client ID f45ec3ad-32f0-4c06-8b69-47682afe0216

EXAMPLE 13​

'

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 14​

Connect-M365Advisor -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​

-SendMail​

If specified, the cmdlet will include the scope to send email (Mail.Send).

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-SendTeamsMessage​

If specified, the cmdlet will include the scope to send a channel message in Teams (ChannelMessage.Send).

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Privileged​

If specified, the cmdlet will include the scopes for read write API endpoints. This is currently required for querying global admin roles in PIM.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-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: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Environment​

The environment to connect to. Default is Global. Supported values include China, Germany, Global, USGov, USGovDoD.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: Global
Accept pipeline input: False
Accept wildcard characters: False

-AzureEnvironment​

The Azure environment to connect to. Default is AzureCloud. Supported values include AzureChinaCloud, AzureCloud, AzureUSGovernment.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: AzureCloud
Accept pipeline input: False
Accept wildcard characters: False

-ExchangeEnvironmentName​

The Exchange environment to connect to. Default is O365Default. Supported values include O365China, O365Default, O365GermanyCloud, O365USGovDoD, O365USGovGCCHigh.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: O365Default
Accept pipeline input: False
Accept wildcard characters: False

-TeamsEnvironmentName​

The Teams environment to connect to. Default is O365Default.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Service​

The services to connect to such as Azure, Dataverse (for Copilot Studio tests), EXO, and SharePoint Online. Default is Graph.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: Graph
Accept pipeline input: False
Accept wildcard characters: False

-TenantId​

The Tenant ID to connect to, if not specified the sign-in user's default tenant is used.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-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/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#use-delegated-access-with-a-custom-application-for-microsoft-graph-powershell

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 7
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-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 M365Advisor app registration by adding an http://localhost redirect URI and AllSites.FullControl delegated SharePoint permission.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 8
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-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: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 9
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-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: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 10
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction​

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

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.

INPUTS​

OUTPUTS​

NOTES​

https://m365advisor.dev/docs/commands/Connect-M365Advisor