Forum Discussion
Tim_Opie
Mar 08, 2023Copper Contributor
Adding B2B guests and adding to security group
Hi, New-ish to Powershell so hoping this isn't a dumb question. It all seems to work as parts but wont run as a whole. The inviting the guest works, just wont add the user to the test security g...
Tim_Opie
Mar 14, 2023Copper Contributor
Think I have somehow got it, this seems to run with a single user, will test with multiples soon. Probably not technically right but it works so far so thats the main thing!
$invitations = import-csv C:\B2BUploads\Test.csv
$messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo
$messageInfo.customizedMessageBody = "Welcome message"
$GroupID = ((Get-AzureADGroup -Filter "Displayname eq 'Test'").ObjectID)
$newuser = foreach ($email in $invitations) {
New-AzureADMSInvitation `
-InvitedUserEmailAddress $email.InvitedUserEmailAddress `
-InvitedUserDisplayName $email.Name `
-InviteRedirectUrl https://google.com `
-InvitedUserMessageInfo $messageInfo `
-SendInvitationMessage $true
}
$newuser `
Start-Sleep -Seconds 2
foreach ($email in $invitations) {
Add-AzureADGroupMember `
-ObjectId $GroupID `
-RefObjectID ((Get-AzureAdUser -All $true | Where-Object {$_.DisplayName -in $email.Name}).ObjectID)
}
Tim_Opie
Mar 14, 2023Copper Contributor
Seems to work for multiple users also, thansk so much for helping me get there!