Exporting data from SQL to create new users in AD

Welcome Forums General PowerShell Q&A Exporting data from SQL to create new users in AD

  • This topic has 5 replies, 2 voices, and was last updated 4 weeks ago by
    Participant
    .
Viewing 5 reply threads
  • Author
    Posts
    • #268724
      Participant
      Topics: 10
      Replies: 18
      Points: 202
      Rank: Participant

      Good morning folks!  As the title says I am exporting data straight from SQL.  This is my testlab I use to run scripts before going into production.  Now I get back data from SQL so that doesn’t seem to be my problem I don’t think.  The output of my data from SQL looks like this.

      Here is my script:

      And here is what I am not understanding the error, which I have been reseaching but haven’t been ablel to find an explanation of why I am getting it:

      Is it the way I have the $Displayname with spaces or????  I am lost on this.  Any help would be appreciated.

      Rich

    • #268754
      Participant
      Topics: 10
      Replies: 18
      Points: 202
      Rank: Participant

      I think I have figured out my problem with properly formed account name.  I guess when I declare my variables just after my foreach I can’t have those spaces.  My OCD gets the best of me when I want to properly align stuff LOL :).  Now my problem I am having is my switch statement.  I declare the $costcenter from the output and I know it works because I have done a foreach loop to write-host “$student.Costcenter” and it produces the correct results so depending on what those results are should work in my switch statement I would think but it doesn’t seem to be working.  If the costcenter is 1211 for example it will look at the switch statement for that and I have 2 variable with with each to one, put it in the correct OU and 2 assign the correct group.  The error I get when running the script now is it is seeing -Path from New-ADUser as empty or null:

       

    • #268766
      Participant
      Topics: 10
      Replies: 18
      Points: 202
      Rank: Participant

      Well I am lost……I am now once again getting the first error and I have literally changed nothing.  What am I missing?

       

    • #268787
      Participant
      Topics: 2
      Replies: 380
      Points: 513
      Helping Hand
      Rank: Major Contributor

      I suspect you have characters in your names that are not permitted.  If you check the data for the students that it’s tripping up on are there any characters in the name?

    • #268850
      Participant
      Topics: 10
      Replies: 18
      Points: 202
      Rank: Participant

      I don’t see any characters in the name at all or spaces.  I have exported it as a csv and checked directly in powershell but don’t see any characters.

    • #268865
      Participant
      Topics: 10
      Replies: 18
      Points: 202
      Rank: Participant

      well i figured it out.  I don’t understand why I had to do this but this is what I had to do after my foreach loop when I declare my variables I had to make these changes:

       

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