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:

  1. Go to Azure Active Directory > App registrations
  2. Select your app (e.g., GraphPowerShellApp)
  3. Go to API permissions > Add a permission
  4. Choose Microsoft Graph > Application permissions
  5. Select the permissions your script requires (e.g., User.Read.All, Group.Read.All)
  6. Click Add permissions

Step 6: Grant Admin Consent

  1. In the same API permissions section
  2. Click Grant admin consent for [Your Org Name]
  3. Confirm the prompt

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