Created
December 7, 2023 04:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = "[email protected]" | |
inviteRedirectUrl = "https://myapps.microsoft.com" | |
sendInvitationMessage = $true | |
invitedUserMessageInfo = @{ | |
messageLanguage = "en-US" | |
customizedMessageBody = "Welcome to the team, Daniel!" | |
ccRecipients = @( | |
@{ | |
emailAddress = @{ | |
name = "Admin" | |
address = "[email protected]" | |
} | |
} | |
) | |
} | |
} | |
# 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