User creation with PowerShell - Login name format

This topic is resolved

Share
Viewing 4 reply threads
  • Author
    Posts
    • #1554083
      Steven
      Participant
      Post count: 23
      Member Points: 713
      Rank: Level 2

      Hello folks,

      I want to format the login name to create user accounts with PowerShell. Since I may use this script for another company with a different sAMAccount and UserPrincipalName format, I would like to vary that part in my script.

      For instance, John Doe could be:

      1. jdoe
      2. john.doe
      3. john-d

      I am unsure if regex is the go-to or if I just should ‘hardcode’ it.

      Cheers,
      Steven

      0
    • #1554084
      Leos Marek
      Moderator
      Post count: 173
      Member Points: 9,304
      Rank: Level 3

      Hi Steven,

      not sure if regex is a good option.
      guess the easiest way is to code those options using substring, split and other available methods.

      0
    • #1554109
      Mike J
      Participant
      Post count: 4
      Member Points: 131
      Rank: Level 2

      Here’s a function I tossed together that you could call.

      2+

      Users who have liked this topic:

      • avatar
      • avatar
    • #1554110
      Steven
      Participant
      Post count: 23
      Member Points: 713
      Rank: Level 2

      That is actually what I was looking for. Thanks a lot. May I use it with you permission in my script (I can share it all) ? I have to admit, I am not familiar with using Switch in PowerShell yet.

      For those who asked themselves why would I want to do that? The reason is simple, I want to avoid human mistake when you are doing a repetitive task, it is easy to miss or do typos.

      0
    • #1554111
      Mike J
      Participant
      Post count: 4
      Member Points: 131
      Rank: Level 2

      Oh by all means take it.  Code is meant to be copied and manipulated.  Play with it, change it.  It’s not perfect -just a framework to explore toys like parameters with validate options or switch.

      Remember: With Functions in powershell, the function needs to be in the script BEFORE it’s called.. that loads it into memory so “get-samaccountname” can be used

      0
Viewing 4 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account