Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Created December 7, 2023 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstreefkerk/b260c360b239e857e73d80ab3d9d2787 to your computer and use it in GitHub Desktop.
Save dstreefkerk/b260c360b239e857e73d80ab3d9d2787 to your computer and use it in GitHub Desktop.
Invite Entra ID Guests with a customised message body and a specific CC recipient using Invoke-MgGraphRequest
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "User.Invite.All"
# Microsoft Graph API endpoint for invitations
$graphApiUrl = "https://graph.microsoft.com/v1.0/invitations"
# Create the invitation object
$invitation = @{
invitedUserDisplayName = "Daniel Streefkerk"
invitedUserEmailAddress = "daniel@example.com"
inviteRedirectUrl = "https://myapps.microsoft.com"
sendInvitationMessage = $true
invitedUserMessageInfo = @{
messageLanguage = "en-US"
customizedMessageBody = "Welcome to the team, Daniel!"
ccRecipients = @(
@{
emailAddress = @{
name = "Admin"
address = "cc_address@example.com"
}
}
)
}
}
# Convert the invitation object to JSON
$json = $invitation | ConvertTo-Json -Depth 4
# Send the invitation
$response = Invoke-MgGraphRequest -Uri $graphApiUrl -Body $json -Method POST
# Output the response
$response
# Disconnect from Microsoft Graph when done
Disconnect-MgGraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment