need a better way to create multiple OUs from csv

Welcome Forums General PowerShell Q&A need a better way to create multiple OUs from csv

Viewing 3 reply threads
  • Author
    Posts
    • #269675
      Participant
      Topics: 138
      Replies: 287
      Points: 449
      Rank: Contributor

      I have this notepad ++ file:

      and this script:

      which is reading this csv:

      ..and realizing this is still gonna take a lot of manual work.

      Is there a way to either massage the notepad ++ file to create the required (4) sub-OUs for all those Parent OUs in the first list?

      thank you

    • #269729
      Senior Moderator
      Topics: 9
      Replies: 1420
      Points: 5,280
      Helping Hand
      Rank: Community MVP

      New-ADOrganizationalUnit cmdlet supports pipeline input, so you can keep the headers of CSV file as same as input Parameters of the cmdlet then just pipe the Import-CSV output to New-ADOrganizationalUnit cmdlet.

    • #270050
      Participant
      Topics: 16
      Replies: 1855
      Points: 3,568
      Helping Hand
      Rank: Community Hero

      If I understand, you have root or core OU that needs to be created first, then you can try to sort on Path.

      Sorting should have the shorter paths first so the root OU is created first and then the sub OUs:

      Another important piece is specifying a domain controller, otherwise you could create one OU on DC1 another on DC2 and then get errors because the root OU doesn’t exist:

    • #270595
      Participant
      Topics: 138
      Replies: 287
      Points: 449
      Rank: Contributor

      I have all my Root OUs created but I was looking for a way to create a better input file OR a better script for the input file (a list of various OU paths that were different for the first two levels, and then all the same after that). Thank you

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