ShiftNick

Update UPN

Dec 23rd, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Generates a list of users from OU listed in SearchBase that have a .LOCAL upn and are enabled
  2. $users = Get-ADUser -Searchbase 'OU=OU,DC=DOMAIN,DC=Local' -Filter {(UserPrincipalName -like '*.local') -and (Enabled -eq $true)}
  3.  
  4. #loop through each user in the list
  5. foreach($user in $users){
  6.  
  7.     #Generates the first half of the UPN as firstname.lastname
  8.     $upn = "$($user.Givenname)" + '.' + "$($user.Surname)"
  9.  
  10.     #sets the UPN of the account to the previously created $UPN variable @domain.local
  11.     Set-Aduser -Identity $user.SamAccountName -UserPrincipalName "[email protected]"
  12.  
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment