Setting Active Directory OU '-Path' parameter

This topic contains 2 replies, has 2 voices, and was last updated by  thickgit 4 years, 4 months ago.

  • Author
    Posts
  • #8502

    thickgit
    Participant

    Evening All,

    Quick one...

    I'm trying to write a script to help with user AD account creation. (Import-CSV and New-ADUser)

    One of the CSV file headers is 'Area Number'. The column's cell contents will contain only either a 1, 2 or 3 (and unfortunately not 'Area1', 'Area2' or 'Area3'). The format of the input CSV file can't be changed.

    I'm trying to set the -path parameter to place the new user in the correct OU:

    'ou=Area1,ou=suppliers,ou=Europe,dc=company,dc=com'

    However, I can't get the first part (ou=Area) to work. I've tried variations of:

    'ou=Area + $_."Area Number",ou=suppliers,ou=Europe,dc=company,dc=com'

    I've messed around with the positioning of the quotes and the '+' symbol (including and omitting it).

    I'm sure this is something simple that I'm going to kick myself over.

    Please put me out of my misery!

  • #8509

    Richard Siddaway
    Moderator

    Either of these should work

    Import-Csv area.csv |
    foreach {
    
    'ou=Area' + $_."Area Number" +',ou=suppliers,ou=Europe,dc=company,dc=com'
    
    "ou=Area$($_.'Area Number'),ou=suppliers,ou=Europe,dc=company,dc=com"
    
    }
    

    assuming a CSV file of

    "Area Number"
    1
    2
    3
    2
    3
    1
    5

  • #8510

    thickgit
    Participant

    I tried them both.

    The 2nd one worked. Many thanks for your help, Richard. Much appreciated!

You must be logged in to reply to this topic.