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
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
TenantId | String | Microsoft Entra tenant ID used for app authentication. | Yes | - |
ClientId | String | Application (client) ID. | Yes | - |
ClientSecret | String | Client secret for app-based authentication. | Yes | - |
AutoInstall | Boolean | Automatically installs Microsoft.Graph when missing. | No | False |
LogLocation | String | Log destination path for connection checks. | No | None |
ShowInformations | Boolean | Emits additional diagnostic information during validation. | No | False |
Example
$ok = Test-MgGraphConnection `
-TenantId "00000000-0000-0000-0000-000000000000" `
-ClientId "11111111-1111-1111-1111-111111111111" `
-ClientSecret $secret `
-AutoInstall