• Home
  • BLOGS

Menu
  • Home
  • BLOGS
09 January 2020

Active Directory Script – update object name or displayname

Written by Ryan Wilson

Get-Content .\usersToUpdate.txt |
Get-ADUser -Properties middleName |
ForEach {
# The next lines are used to the the “Display Name” seen in ADUC. Comment these out if you do not want to update the DisplayName
If ($_.middleName -eq $null) {
Set-ADUser $_ -DisplayName ($_.GivenName + ” ” + $_.Surname)
}
Else {
Set-ADUser $_ -DisplayName ($_.GivenName + ” ” + $_.middleName + ” ” + $_.Surname)
}
# These lines set the Name attribute (“Full Name” attribute in ADUC)
If ($_.middleName -eq $null) {
Rename-ADObject $_.DistinguishedName -NewName ($_.GivenName + ” ” + $_.Surname)
}
Else {
Rename-ADObject $_.DistinguishedName -NewName ($_.GivenName + ” ” + $_.middleName + ” ” + $_.Surname)
}
}

This will read in a list of sAMAccountNames (one per line) from a text file named usersToUpdate.txt and then make the changes. Comment out the displayname lines if you only need to update the Name and vice versa. It will check for the presence of a middleName to be sure that an extra space isn’t introduced.

Leave a Reply

Cancel reply

Recent Posts

  • Serverless LAPS using Azure function and Secret Key Vaults
  • MS Teams – export team owners
  • Deploy AppLocker in Intune- Block CMD and PowerShell
  • Autopilot Hybrid Joined device built outside the corporate network
  • Add a SharePoint site as a custom app within Teams
  • Query all MS Teams and Export list of guests added to each Team site
  • MS Flow – adding timestamp in the middle of a filename whilst retaining file extension
  • MS Flow to export outlook attachment into a Teams channel and notify users with an adaptive card
  • Unlicense Office suite using last 5 characters
  • Azure Information Protection – We were not able to find the Information Rights Management template.

Recent Comments

  • Ged on MS Flow to export outlook attachment into a Teams channel and notify users with an adaptive card
  • film on Autopilot Hybrid Joined device built outside the corporate network
  • Ryan Wilson on Azure Information Protection – We were not able to find the Information Rights Management template.
  • BurtonMBrohl on Azure Information Protection – We were not able to find the Information Rights Management template.
  • Ryan Wilson on Azure Information Protection – We were not able to find the Information Rights Management template.
  • RayeXDuesing on Azure Information Protection – We were not able to find the Information Rights Management template.
  • TroyTHulette on Azure Information Protection – We were not able to find the Information Rights Management template.
  • NildaZAdamos on Azure Information Protection – We were not able to find the Information Rights Management template.
  • Ryan Wilson on Azure Information Protection – We were not able to find the Information Rights Management template.
  • NoahVSolak on Azure Information Protection – We were not able to find the Information Rights Management template.

Archives

  • March 2021
  • December 2020
  • November 2020
  • October 2020
  • August 2020
  • June 2020
  • May 2020
  • February 2020
  • January 2020
  • December 2019
  • July 2019

Categories

  • IT Blogs (20)
© Copyright 2017. Theme by BloomPixel.