User Last name need change to UPPERCASE for all users

Welcome Forums General PowerShell Q&A User Last name need change to UPPERCASE for all users

Viewing 5 reply threads
  • Author
    Posts
    • #197567
      Participant
      Topics: 3
      Replies: 2
      Points: 17
      Rank: Member

      Hi guys,

      I have a requirement to change all my AD users last name should change to UPPERCASE letters

      I have more than 1000 users so i can't change one by one manually.

      I dont want to change logon name.It should be same like before.

      i want to change only surname to uppercase.

      Please let me know is there any script or any alternative to get this done.

      The reason behind this is the admin who worked before me did not followed the proper process while creating.

      So i want to changes to done on only particular OU not all.

      I have some services accounts in other OU's. I dont want to touch them.

      Please suggest.

      Thank you

    • #197579
      Senior Moderator
      Topics: 8
      Replies: 1153
      Points: 4,006
      Helping Hand
      Rank: Community Hero

      Possible, If you have not tried anything so far for this, would suggest you to start putting up some code with the help of the help documentation of Get-ADUser and Set-ADUser cmdlets, may be help doc for Foreach-Object as well to start with. Folks here will help you when you get stuck.

    • #197582
      Participant
      Topics: 3
      Replies: 2
      Points: 17
      Rank: Member

      Possible, If you have not tried anything so far for this, would suggest you to start putting up some code with the help of the help documentation of Get-ADUser and Set-ADUser cmdlets, may be help doc for Foreach-Object as well to start with. Folks here will help you when you get stuck.

      yes i tried below script but its throwing some kind of error

      $targetUsers = Get-ADuser -SearchBase 'OU=india,DC=study,DC=com'
      $targetUsers | foreach-object {
      set-aduser $_ -Surname $_.surname.toupper()
      }
      

      error : cmdlet Get-ADUser at command pipeline position 1
      Supply values for the following parameters:
      (Type !? for Help.)
      Filter:

      • This reply was modified 1 week, 4 days ago by kvprasoon. Reason: code formatting
    • #197585
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      When you say uppercase, what exactly do mean? Normally, you want to name in Title Case, you see:

      #PSTip How to convert words to Title Case

      The issue with Title Case is normally names with prefixes like McDonald:

      $names = 'smith','mcdonald','decost', 'de cost'
      foreach ($name in $names) {
          ((Get-Culture).TextInfo).ToTitleCase($name)
      }
      

      Output:

      Smith
      Mcdonald
      Decost
      De Cost
      

      If you want all characters to Uppercase, while this is easy, I would not recommend it as Active Directory feeds many other business systems, signatures, etc. and it appears like someone is screaming your name in all of these systems. I usually have to fix applicants that use all caps on everything in Applicant Tracking Systems when they apply for a job before they are placed into HRM systems that feed into Active Directory. Start by collecting all of the names with Get-ADUser and if all users in scope are under an OU use the -SearchBase parameter and add -Properties SurName.

      $users = Get-ADUser -Filter * -Properties SurName
      

      Once you have the names, then apply the code to do the text transformation to validate and then you can use Set-ADUser to update the users.

    • #197594
      Participant
      Topics: 3
      Replies: 2
      Points: 17
      Rank: Member

      When you say uppercase, what exactly do mean? Normally, you want to name in Title Case, you see:

      #PSTip How to convert words to Title Case

      The issue with Title Case is normally names with prefixes like McDonald:

      PowerShell
      5 lines

      1
      2
      3
      4
      5
      $names = 'smith','mcdonald','decost', 'de cost'
      foreach ($name in $names) {
      ((Get-Culture).TextInfo).ToTitleCase($name)
      }
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Output:

      PowerShell
      5 lines

      1
      2
      3
      4
      5
      Smith
      Mcdonald
      Decost
      De Cost
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      If you want all characters to Uppercase, while this is easy, I would not recommend it as Active Directory feeds many other business systems, signatures, etc. and it appears like someone is screaming your name in all of these systems. I usually have to fix applicants that use all caps on everything in Applicant Tracking Systems when they apply for a job before they are placed into HRM systems that feed into Active Directory. Start by collecting all of the names with Get-ADUser and if all users in scope are under an OU use the -SearchBase parameter and add -Properties SurName.

      1
      2
      $users = Get-ADUser Filter * Properties SurName
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Once you have the names, then apply the code to do the text transformation to validate and then you can use Set-ADUser to update the users.

      Hello Rob,

      # Retrieve the Surname property (the sn attribute) of all users in the specified OU.
      $Users = Get-ADUser -SearchBase "ou=Sales,ou=West,dc=domain,dc=com" -Filter {Surname -Like "*"} | Select DistinguishedName, Surname
      
      ForEach ($User In $Users)
      {
          $DN = $User.DistinguishedName
          $Name = $User.Surname
      
          # Desired case.
          $NewName = $Name.ToUpper() }
      
      this above script worked for me it changed to all my surnames to uppercase but only thing is in DISPLAY NAME its still showing small case
      hhow can i change that ?
      
      

       

       

    • #198302
      Participant
      Topics: 2
      Replies: 16
      Points: 69
      Helping Hand
      Rank: Member

      $User.DisplayName ???

Viewing 5 reply threads
  • You must be logged in to reply to this topic.