Skip to content
Back to skills

Powershell Graph Api

BSecurity

Use when calling Microsoft Graph API from PowerShell.

  • 2 stars
  • 0 votes
  • 0 copies
  • 7 views
  • Added September 10, 2026
ai-agentsgoshellazureapidocumentation

Works with

  • cli
  • api

Security analysis

B75/100
  • criticalAccesses sensitive system or user directories
  • criticalSends environment variables or credentials to an external URL

Pro shows the line behind each finding and how to fix it

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill powershell-graph-api --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Powershell Graph Api?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Powershell Graph Api
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-powershell-graph-api/badge)](https://www.skillsdirectory.com/skills/loopyluci-powershell-graph-api)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: powershell-graph-api
description: "Use when calling Microsoft Graph API from PowerShell."
category: software-development
tags: [powershell, graph, microsoft, api, azure, entra]
---
# Microsoft Graph API with PowerShell

Calling Microsoft Graph API from PowerShell.

## Authentication

```powershell
# Device code flow (interactive)
$body = @{
    client_id = "your-client-id"
    scope = "User.Read Mail.Read Files.Read.All"
} | ConvertTo-Json
$deviceCode = Invoke-RestMethod -Method Post `
    -Uri "https://login.microsoftonline.com/organizations/oauth2/v2.0/devicecode" `
    -Body $body -ContentType "application/json"
Write-Host $deviceCode.message  # User visits URL and enters code

# Poll for token
do {
    Start-Sleep -Seconds 5
    $token = Invoke-RestMethod -Method Post `
        -Uri "https://login.microsoftonline.com/organizations/oauth2/v2.0/token" `
        -Body @{
            grant_type = "urn:ietf:params:oauth:grant-type:device_code"
            client_id = "your-client-id"
            device_code = $deviceCode.device_code
        }
} until ($token.access_token)
```

## Basic Queries

```powershell
$headers = @{ Authorization = "Bearer $($token.access_token)" }
$base = "https://graph.microsoft.com/v1.0"

# Get current user
$me = Invoke-RestMethod -Uri "$base/me" -Headers $headers
$me.displayName

# Get user's messages
$messages = Invoke-RestMethod -Uri "$base/me/messages?`$top=10" -Headers $headers
$messages.value | Select-Object subject, receivedDateTime

# Get files from OneDrive
$files = Invoke-RestMethod -Uri "$base/me/drive/root/children" -Headers $headers
$files.value | Select-Object name, size, lastModifiedDateTime
```

## Using Graph PowerShell SDK

```powershell
# Install
Install-Module Microsoft.Graph -Scope CurrentUser

# Connect
Connect-MgGraph -Scopes "User.Read", "Mail.Read", "Files.Read.All"

# Get current user
Get-MgUser -UserId me | Select-Object DisplayName, Mail, UserPrincipalName

# List users
Get-MgUser -All -Top 100 | Select-Object DisplayName, UserPrincipalName

# Get messages
Get-MgUserMessage -UserId me -Top 10 | Select-Object Subject, ReceivedDateTime

# Get files
Get-MgUserDriveRootChild -UserId me | Select-Object Name, Size
```

## Common Tasks

```powershell
# Search for users
Get-MgUser -Search '"DisplayName:John"' -ConsistencyLevel eventual

# Send email
$body = @{
    message = @{
        subject = "Hello from Graph"
        body = @{ contentType = "Text"; content = "This is a test message" }
        toRecipients = @(@{ emailAddress = @{ address = "user@contoso.com" } })
    }
}
Send-MgUserMail -UserId me -BodyParameter $body

# Create team
New-MgTeam -DisplayName "New Team" -Description "Created via Graph API"
```

## Pitfalls

- Graph requires registered app in Azure AD/Entra ID
- Permissions are consented per-user or admin -- some need admin consent
- Pagination uses `@odata.nextLink` -- use `-All` flag in SDK
- Beta API endpoints differ from v1.0 -- check documentation
- SDK modules are large -- install only needed submodules (`Microsoft.Graph.Users`, etc.)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.