Skip to content

Graph SDK Powershell

Learning

Security

Azure Automation

Uddate Process

Work

Check

Get-InstalledModule | Where-Object {$_.Name -match "Microsoft.Graph"}

Install

Install-Module -Name "Microsoft.Graph"

Update

Update-Module Microsoft.Graph

Uninstall (all)

Uninstall-Module Microsoft.Graph

# Uninstall all Sub-modules of Graph
Get-InstalledModule Microsoft.Graph.* | ForEach-Object { if($_.Name -ne "Microsoft.Graph.Authentication") {
    Uninstall-Module $_.Name }
}

# Uninstall the dependant module
Uninstall-Module Microsoft.Graph.Authentication

Connect with Delegated Access

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Read.All"

# Get All users
$users = Get-MgUser
$users | Select-Object DisplayName, UserPrincipalName, Mail

Connect with App ID and Certificate

# App Config
$TenantID = "<placeholder>"
$ClientID = "<placeholder>" # App ID
$CertThumbPrint = "<placeholder>"

# Connect to Microsoft Graph using App
Connect-MgGraph -ClientID $ClientID -TenantId $TenantID -CertificateThumbprint $CertThumbPrint

Connect with Client Secret

# App Registration details
$TenantID = "<placeholder>"
$ClientID = "<placeholder>"
$ClientSecret = "<placeholder>"

$Body =  @{
    Grant_Type    = "client_credentials"
    Scope         = "https://graph.microsoft.com/.default"
    Client_Id     = $ClientID
    Client_Secret = $ClientSecret
}

$Connection = Invoke-RestMethod `
    -Uri https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token `
    -Method POST `
    -Body $body

# Get the Access Token
$Token = $Connection.access_token

# Connect to Microsoft Graph
Connect-MgGraph -AccessToken $Token

Check Size

Get-Variable Max*Count
$Modules = Get-Module -ListAvailable
$ListModules = foreach ($Module in $Modules) {
    [PScustomObject] @{
        Name          = $Module.Name
        Version       = $Module.Version
        FunctionCount = ($Module.ExportedFunctions).Count
    }
}
$ListModules | Sort-Object -Property FunctionCount -Descending | Format-Table -AutoSize

AzureAD Module Migration