Graph PowerShell Basics: How to Set Up an Azure AD App for Microsoft Graph
If you're planning to use Graph PowerShell for automation, you'll need to register an Azure AD app and assign it the right permissions. Here's a quick guide to help you get started:
Step 1: Install the Microsoft Graph PowerShell SDK
Open PowerShell and run:
Install-Module Microsoft.Graph -Scope CurrentUser
Step 2: Connect to Microsoft Graph (Optional for Setup)
If you want to experiment with delegated permissions first:
Connect-MgGraph -Scopes "Application.ReadWrite.All", "User.Read.All"
Step 3: Register a New Azure AD Application
Run this to register the app:
$app = New-MgApplication -DisplayName "GraphPowerShellApp"
Take note of the AppId and Id from the output — you'll need them later.
Step 4: Create a Client Secret
Create a secure password (client secret) for the app:
$secret = Add-MgApplicationPassword -ApplicationId $app.Id -PasswordCredential @{ displayName = "GraphSecret" }
Copy the SecretText somewhere safe. It won't be shown again.
Step 5: Assign API Permissions (Azure AD UI)
Now head over to the Azure Portal:
Step 6: Grant Admin Consent
Step 7: Authenticate Using the App
Here's how to connect using your app's credentials:
$ClientId = "<Your AppId>"
$TenantId = "<Your TenantId>"
$ClientSecret = "<Your SecretText>"
$SecureSecret = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($ClientId, $SecureSecret)
Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $Credential
You're All Set!
You now have a dedicated app to run Graph PowerShell scripts securely — perfect for scheduled jobs, unattended automation, and scalable management across Microsoft 365.
© m365corner.com. All Rights Reserved. Design by HTML Codex