Microsoft Graph - API Connect
Synopsis: Additional notes on 'Connect-MG' commands for repeat use in PowerShell Scripts
Published April 22th, 2026
Last Modified: April 22th, 2026
Intro: Microsoft phased out SharePoint PNP commands sometime ago, and has steadily pushed towards Graph commands. This outlines some notes for future me.
Published April 22th, 2026
Last Modified: April 22th, 2026
Intro: Microsoft phased out SharePoint PNP commands sometime ago, and has steadily pushed towards Graph commands. This outlines some notes for future me.
Quick Run Down
-
1.)Registered App
2.) PowerShell Example
3.) Troubleshooting
Registered App
- In https://portal.azure.com > Registered Apps > Create a new app for a single tenant.
- "Microsoft Graph - API"
- Add delegate permissions : App Only
- SharePoint needs "sites.read.all"
- User audits might need users.read.all (WIP)
- Approve the Admin Consent
- Generate client secret info, export Value, Client/APP ID, and Tenant ID to another notepad for use in the connection script below
PowerShell Example
#GRAPH API INFORMATION
$TenantId = ""
$ClientId = ""
$ClientSecret = ""
#CONNECT TO GRAPH
$SecureSecret = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force
$ClientCredential = New-Object System.Management.Automation.PSCredential (
$ClientId,
$SecureSecret
)
Connect-MgGraph `
-TenantId $TenantId `
-ClientSecretCredential $ClientCredential `
-NoWelcome
Troubleshooting Tips
- PlaceHolder li>