Turn fullname into AD name

Welcome Forums General PowerShell Q&A Turn fullname into AD name

This topic contains 5 replies, has 4 voices, and was last updated by

Jon
 
Participant
1 year, 2 months ago.

  • Author
    Posts
  • #80378

    Participant
    Points: 0
    Rank: Member

    Hey guys,

    So im stuck here. I've done this a bunch of times in SQL but never in PS. I have a full name like "John Smith" that i am writing a script to auto change password when its expired. However, AD does not like "John Smith" so i need to change it to "JSmith".
    In the past for SQL ive used a combination of charindex, length, substring etc etc. But for the life of me i am drawing a blank on how to do this in PS. Any help would be great!

    Thank you

  • #80381

    Participant
    Points: 0
    Rank: Member

    This example should work.

    $user = "Joe Smith"
    $user.Substring(0,1)+$user.Split(" ")[1]

  • #80384

    Participant
    Points: 0
    Rank: Member

    Thank you soooo much. This works great!

  • #80386

    Participant
    Points: 5
    Rank: Member

    Hi,

    Are you trying to change the name in AD?
    Can't you just use:

    $User = Get-ADUser -identify John.Smith
    Set-ADUser -Identity $User -UserPrincipalName JSmith 
    

    Sorry if im not understanding the question?

    • #80387

      Participant
      Points: 5
      Rank: Member

      Sorry, i've just now understood what you are doing.
      As rick said 🙂

  • #80401
    Jon

    Participant
    Points: 37
    Rank: Member

    I frequently get a list of users that need permission to whatever in the form of display name. So I dump the display names in a text file and do this:

    gc C:\scripts\displaynames.txt | % {Get-ADUser -LDAPfilter "(DisplayName=$_)"} | select samaccountname

The topic ‘Turn fullname into AD name’ is closed to new replies.