Setting Active Directory OU '-Path' parameter

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!

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

I tried them both.

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