Skip to content

Instantly share code, notes, and snippets.

@1RedOne
Last active August 8, 2018 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1RedOne/1437ac12335ebf3761de6314a1c0a0a7 to your computer and use it in GitHub Desktop.
Save 1RedOne/1437ac12335ebf3761de6314a1c0a0a7 to your computer and use it in GitHub Desktop.
A scratch of swapping a dash for a period in AD>
if ($user.Surname){
"$user has a surname"
$newSurname = $user.Surname.ToUpper()
"changing to $newSurname"
$user | Set-ADUser -Surname $newSurname -WhatIf
}
$users =Get-ADUser -Filter * -Properties telephonenumber
#Step through each object in $users, calling the current object $user
ForEach ($user in $users){
#If the user has a telephone number property, they have a number set in AD. If so, run this next script block
if ($user.telephonenumber){
#Make a temporary variable to hold the users new number
$newphone = $user.telephonenumber.Replace('-','.')
#Every string in .net has a .Replace method. We use it to swap a '-' for a '.'
#Echo out to the screen what we're doing
"changing $($user.Name) Phone from $($user.telephonenumber) to $newphone"
#Set the phonenumber in AD
$user | Set-ADUser -OfficePhone $newphone -Verbose -WhatIf
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment