Forum Discussion
TonyRedmond
Nov 27, 2026MVP
Using PowerShell Here-Strings with Graph APIs
A reader was curious about the way of passing data to Graph API requests as shown in an article. It's because we used PowerShell here-strings to pass request bodies to Graph API requests. Normally, we use hash tables to create a request body containing several parameters and their values, but sometimes it’s easier to use a here-string for the reasons explained here.
https://office365itpros.com/2026/11/27/here-string-powershell/
1 Reply
- mixrotechlo512Brass Contributor
Best solution: Use PowerShell Here-Strings to send JSON directly to Microsoft Graph API.
powershell
$Body = @"
{
"displayName": "IT Support Team",
"mailEnabled": true,
"mailNickname": "ITSupport",
"securityEnabled": false,
"groupTypes": ["Unified"]
}
"@
Invoke-MgGraphRequest -Method POST `
-Uri "https://graph.microsoft.com/v1.0/groups" `
-Body $Body `
-ContentType "application/json"
Why use Here-Strings?
- No need to create hash tables.
- Easy to copy and edit JSON.
- Preserves readable JSON formatting.
Tip: Use Here-Strings for quick Graph API requests and hash tables when working with dynamic PowerShell variables.