Skip to content

Instantly share code, notes, and snippets.

@hunzo
Last active January 28, 2022 05:14
Show Gist options
  • Select an option

  • Save hunzo/0ff23b6d1d9c0b00fcda749e63ed688c to your computer and use it in GitHub Desktop.

Select an option

Save hunzo/0ff23b6d1d9c0b00fcda749e63ed688c to your computer and use it in GitHub Desktop.
example ps script
# login as Global Admin Account
$User = "[email protected]"
$PWord = ConvertTo-SecureString -String "global_admin_password" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
$teamsurl = "https://link_to_event" # Link to event
# $cred = Get-Credential
Connect-AzureAD -Credential $cred
Connect-MsolService -Credential $cred
Connect-MicrosoftTeams -Credential $cred
$exosession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $exosession
# Get User from Recyclebin
Get-MsolUser -ReturnDeletedUsers
Get-MsolUser -ReturnDeletedUsers -All | Where-Object { $_.UserPrincipalName -like "*sn*"}
Get-MsolUser -ReturnDeletedUsers -All | Where-Object { $_.UserPrincipalName -like "*sn*"} | Remove-MsolUser -RemoveFromRecycleBin
Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin
# Example:
# Send Link Invite
New-AzureADMSInvitation -InvitedUserEmailAddress [email protected] -InviteRedirectURL $teamsurl -SendInvitationMessage $true
# Bulk invites
$invitations = import-csv .\file.csv
foreach ($email in $invitations) {$email.email}
foreach ($email in $invitations) {New-AzureADMSInvitation -InvitedUserEmailAddress $email.InvitedUserEmailAddress -InvitedUserDisplayName $email.Name -InviteRedirectUrl $teamsurl -InvitedUserMessageInfo $messageInfo -SendInvitationMessage $true}
# Add user to Microsoft 365 Group
Add-UnifiedGroupLinks -Identity "Microsoft 365 Group" -LinkType Members -Links "[email protected]"
# Bulk Add to Microsoft 365 Group
$invitations = import-csv .\file.csv
foreach ($email in $invitations) {$email.email}
foreach ($email in $invitations) {Add-UnifiedGroupLinks -Identity "Microsoft 365 Group" -LinkType Members -Links $email.email}
# CSV example
# email
# [email protected]
# [email protected]
# [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment