Index
- Fix Duplicate Email Addresses for On-premises Mail-Enabled Objects
- Fix Duplicate User Principal Name for On-premises Active Directory Users
- Office 365: License Users for Office 365 Workloads
- Delete multiple users
- Flip UPN for all the users except Global Admin
- Export the list of users who are on “contoso.onmicrosoft.com” domain to a CSV
- Retrieve list of Global Admin
Fix Duplicate Email Addresses for On-premises Mail-Enabled Objects
- Download the PS file from here: http://gallery.technet.microsoft.com/scriptcenter/Fix-Duplicate-Email-525089e4
Fix Duplicate User Principal Name for On-premises Active Directory Users
- Download the PS file from here: http://gallery.technet.microsoft.com/scriptcenter/Fix-Duplicate-User-d92215ef
Office 365: License Users for Office 365 Workloads
- Download the PS file from here: http://social.technet.microsoft.com/wiki/contents/articles/11349.office-365-license-users-for-office-365-workloads.aspx
Delete Multiple Users
Get-MsolUser -all | select DisplayName,UserPrincipalName,ObjectID | export-csv C:\temp.csv // Ensure you remove GA's from the Excel Sheet to avoid tenant lockout.
$imp = Import-CSV c:\temp.csv
$imp | ForEach {Remove-MSOLUser -ObjectID $_.ObjectID -force}
$imp | ForEach {Remove-MSOLUser -ObjectID $_.ObjectID –RemoveFromRecycleBin -force}
Flip the UPN for All Users Except the Global Admin
I’ve observed many cases where if the customer is migrated from Live@Edu to Office365, the users are not able to reset the password or login. We see that the user account is managed user in MSODS but it is still shows as federated in OrgID and that is the reason you cannot change the password.
In this scenario common practice we follow is to flip the user’s UPN from vanity domain to tenant domain and flip it back to vanity domain.
Following commands can be used to do this for bulk users which will exclude the Global Admin account:
//This will flip the UPN to tenant domain
Get-MsolUser | Where { -Not $_.UserPrincipalName.ToLower().StartsWith(“admin@”) } | ForEach { Set-MsolUserPrincipalName -ObjectId $_.ObjectId -NewUserPrincipalName ($_.UserPrincipalName.Split(“@”)[0] + “@tenant.onmicrosoft.com”) }
//This command will flip the UPN back to vanity domain.
Get-MsolUser | Where { -Not $_.UserPrincipalName.ToLower().StartsWith(“admin@”) } | ForEach { Set-MsolUserPrincipalName -ObjectId $_.ObjectId -NewUserPrincipalName ($_.UserPrincipalName.Split(“@”)[0] + “@vanitydomain.com”) }
Important note – Please note that if the vanity domain is federated we can safely run this commands but if it is managed then flipping UPN will result in setting temporary password for each user.
Export the list of users who are on “contoso.onmicrosoft.com” domain to a CSV
Get-MsolUser -All | Where {$_.UserPrincipalName.ToLower().EndsWith(“@contoso.onmicrosoft.com")} | select UserPrincipalName |export-csv C:\upnchange.csv
Retrieve list of Global Admin
Get-MsolUser -all | select userprincipalname | ForEach-Object {$admin=Get-MsolUserRole -UserPrincipalName $_.userprincipalname; if($admin -ne $null) {Write-Host $_.userprincipalname, ">" ,$admin.name}}