Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #From https://eschrader.com/2017/06/12/sharepoint-online-azure-ad-b2b-custom-email-invites-for-users-using-powershell/
- #1.) Install Azure AD PS module – https://www.powershellgallery.com/packages/AzureADPreview
- #Install-Module -Name AzureADPreview
- #2.) provide O365 tenant admin cred
- $cred = Get-Credential
- Connect-AzureAD -Credential $cred
- #2.a) second cred for O365 email account (merge var with above if for non-demo O365 tenant)
- $adminemailcred = get-credential
- #2.b) External User Security Group ID
- #get-azureadgroup | where-object {$_.DisplayName -ilike "External Users"}
- $groupID = "c9a04711-e307-4370-af42-f48db58f80c5"
- #3.) import CSV, update url and csv location below.
- $invitations = import-csv C:\azure_ad_b2b.csv
- foreach ($email in $invitations) {
- #loop over each user in the CSV and create an invite for that user but does not email the user
- $result= New-AzureADMSInvitation -InvitedUserEmailAddress $email.InvitedUserEmailAddress -InvitedUserDisplayName $email.Name -InviteRedirectUrl https://eschrader.sharepoint.com/sites/extranet -InvitedUserMessageInfo $messageInfo -SendInvitationMessage $false
- $inviteurl = $result.InviteRedeemUrl
- $userid = $result.InvitedUser.Id
- #automatically add the new user to your Security Group
- Add-AzureADGroupMember -ObjectId $groupID -RefObjectId $userid
- #send the user a custom email from your Office 365 tenant. Supports HTML.
- #Configuration variables for Email
- $EmailTo = $result.InvitedUserEmailAddress
- $EmailFrom = "Eric Schrader <eric@eschradrr.onmicrosoft.com>"
- $EmailSubject = "INVITE: Eschrader Extranet"
- $SupportEmail = "support@eschradrrr.com"
- $SmtpServer = "smtp.office365.com"
- $InviteUrl = $inviteurl
- $DisplayName = $result.Name
- #HTML Template
- $EmailBody = @"
- <header>
- <img src="https://ericschrader.files.wordpress.com/2017/05/sileo-logo.png" />
- </header>
- <div>
- <p style="margin-top:20px;">Congrats $DisplayName,</p>
- <p>
- You have been invited to access the Eschrader extranet.
- </p>
- <p>
- <div><a href="$InviteUrl">Sign Up</a></div>
- </p>
- <p>
- If you need further assistance, please contact us <a href="mailto:$SupportEmail">$SupportEmail</a>
- </p>
- </div>
- "@
- Send-MailMessage -To $EmailTo -from $EmailFrom -Subject $EmailSubject -Body $EmailBody -BodyAsHtml -smtpserver $SmtpServer -usessl -Credential $adminemailcred -Port 587
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement