Skip to main content

Connect to Microsoft 365

This page covers Graph connectivity checks used by automation scripts. For full and always-up-to-date details, use Get-Help <FunctionName> -Detailed (or -Examples).

Test-MgGraphConnection

Validate and initialize Microsoft Graph connectivity, with optional auto-install behavior.

Syntax

Test-MgGraphConnection -TenantId <String> -ClientId <String> -ClientSecret <String>
[-AutoInstall] [-LogLocation <String>] [-ShowInformations]

Parameters

ParameterTypeDescriptionRequiredDefault
TenantIdStringMicrosoft Entra tenant ID used for app authentication.Yes-
ClientIdStringApplication (client) ID.Yes-
ClientSecretStringClient secret for app-based authentication.Yes-
AutoInstallBooleanAutomatically installs Microsoft.Graph when missing.NoFalse
LogLocationStringLog destination path for connection checks.NoNone
ShowInformationsBooleanEmits additional diagnostic information during validation.NoFalse

Example

$ok = Test-MgGraphConnection `
-TenantId "00000000-0000-0000-0000-000000000000" `
-ClientId "11111111-1111-1111-1111-111111111111" `
-ClientSecret $secret `
-AutoInstall