Created
January 6, 2014 10:51
-
-
Save janikvonrotz/8281095 to your computer and use it in GitHub Desktop.
PowerShell: Update Obsolete User Principal Names in Office 365 Windows Azure Directory
#PowerShell
#Office365
#ActiveDirectory
This file contains 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
#--------------------------------------------------# | |
# settings | |
#--------------------------------------------------# | |
$OU = "OU=vblusers2,DC=vbl,DC=ch" | |
#--------------------------------------------------# | |
# modules | |
#--------------------------------------------------# | |
Import-Module MSOnline | |
Import-Module MSOnlineExtended | |
Import-Module ActiveDirectory | |
#--------------------------------------------------# | |
# main | |
#--------------------------------------------------# | |
$ADUsers = Get-ADUser -Filter * -SearchBase $OU -Properties GivenName, Surname, DisplayName | |
$Credential = Import-PSCredential $(Get-ChildItem -Path $PSconfigs.Path -Filter "Office365.credentials.config.xml" -Recurse).FullName | |
Connect-MsolService -Credential $Credential | |
$MsolUsers = Get-MsolUser -All | |
$MsolUsers | %{ | |
$MsolUser = $_ | |
$ADUsers | where{($_.GivenName -eq $MsolUser.FirstName) -and | |
($_.Surname -eq $MsolUser.LastName) -and | |
($_.DisplayName -eq $MsolUser.DisplayName) -and | |
($_.UserPrincipalName -ne $MsolUser.UserPrincipalName) | |
} | %{ | |
Write-Host "Change UserPrincipalName for: $($MsolUser.UserPrincipalName) to: $($_.UserPrincipalName)" | |
Set-MsolUserPrincipalName -UserPrincipalName $MsolUser.UserPrincipalName -NewUserPrincipalName $_.UserPrincipalName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment