New-ADUser : The name provided is not a properly formed account name

This topic is resolved

Share
Viewing 8 reply threads
  • Author
    Posts
    • #1554132
      Steven
      Participant
      Post count: 21
      Member Points: 653
      Rank: Level 2

      Hello Folks,

      I have recently put a script together and it is the first time is it giving me such headaches. I have tried to print out each element to confirm that I was able to get the info properly.

      However, when I do run the New-User, I get an error :

      New-ADUser : The name provided is not a properly formed account name
      At line:1 char:

      I am not sure as of why I get that. Knowing when I print out $Name, it shows the proper format and everything is correct. Am I missing something ?

      • This topic was modified 2 months ago by Steven.
      • This topic was modified 2 months ago by Michael Pietroforte. Reason: Changed title
      0
    • #1554146
      Leos Marek
      Moderator
      Post count: 133
      Member Points: 6,405
      Rank: Level 3

      Hi Steven,

      could you briefly describe what are you trying to achieve and also share the CSV? It is a good habit to insert short comments before each script section telling what its supposed to do. It is then easier for others (and also for you after some time) to read the script and get inside quicker.

      Thanks

       

      0
    • #1554150
      Steven
      Participant
      Post count: 21
      Member Points: 653
      Rank: Level 2

      Hello Leos, when I saw I respond I knew I had forgotten to add the important part haha.CSV Attached. It is only in a test mode at the moment. Parameter from CSV can be changed also.

      Goal: Create user with a CSV Template to any given AD.

      Reason: I want to have a simple template that can be carried over and not dependant to human parameters for the most part.

       

      Cheers,

      Steven

       

      Attachments:
      You must be logged in to view attached files.
      0
    • #1554152
      Steven
      Participant
      Post count: 21
      Member Points: 653
      Rank: Level 2

      Hello folks,

       

      So multiple error on my part. First one is sAMAccount parameter is wrong, it should be sAMAccountName. Also, you cannot select special characters in the parameter, therefore my structure was not right (($net + ‘\’ + $login)).

       

      Thanks for reviewing.

      Steven

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

      Hey Steven.  Looks like you’re making progress.  Don’t worry… mistakes are expected and you’ll learn lots from them and pick up other stuff along the way.

      If I could make a suggestion from a little code review?  There is an easier way to do this loop:

      For($i = 0; $i -lt $list.count; $i++){
      $list.givenName[$i]
      }

      You’re showing that you understand the basics of how a loop works.  You’re telling it how to increment, when to stop.  Perfect.  But what if you know you just want to do something with every item in a list?  Start at the beginning, stop when you are out of items.  For this you use: Foreach

      foreach($item in $list)
      {
      $item.givenName
      }

      Try it.  You could also use ($line in $file) -or whatever variable name makes sense to you and the other people reading the code.

      Automation is fun.  Even when it takes 3 times as long to write a script than just do it manually… you might use that code again someday and then you really save time!

      1+

      Users who have liked this topic:

      • avatar
    • #1554154
      PowerMe!
      Participant
      Post count: 24
      Member Points: 1,157
      Rank: Level 3

      Glad that you fixed it.

      Just a note, I tend not use the “xx-yyy” as function names not confuse with the PowerShell’s verb-noun convention (screenshot).  I try to force myself to be creative with ‘_” or capitalization in naming my function!

      0
    • #1554170
      Steven
      Participant
      Post count: 21
      Member Points: 653
      Rank: Level 2

      @MikeJ: Thanks for the advise. I did the modification, it makes more sens. I do added more login type as I face new ones. Yes it may takes triple the time, but just today, I had to create 6 new user, used the script and worked like a charm !

      @PowerMe! : I am not sure to understand you ” I tend not use the “xx-yyy” as function names. ” I checked my functions and they are all verb-noun.

      1+
    • #1554171
      PowerMe!
      Participant
      Post count: 24
      Member Points: 1,157
      Rank: Level 3

      Hi Steven,

      What I meant was just a convention I use. For example, when I crate a function with “get-xxx” or “find-xxx” I should be careful enough not to use the nouns already being used. But may be there is a better way to deal with my confusion!

       

      0
    • #1554187
      Steven
      Participant
      Post count: 21
      Member Points: 653
      Rank: Level 2

      OH ! Now I get it. I thought about it too but I wasn’t sure. I think I will do it eventually if I do use it more often since you have so few words to name your function. Thanks though, it’s a valid point.

      1+
Viewing 8 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