Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Using powershell to import a csv file for OU's

$
0
0

You don’t have to be on a specific server, the previously shared code could be run from any machine with RSAT tools. Otherwise, you would need to use ADSI to create the OU’s:

# OU.csv
#
#”Name”,”Path”
#”MyNewOU1″, “DC=FABRIKAM,DC=COM”
#”MyNewOU2″, “DC=FABRIKAM,DC=COM”
#”MyNewOU3″, “DC=FABRIKAM,DC=COM”

Import-CSV C:\Users\rob\desktop\OU.csv | ForEach{
$OU = [adsi](“LDAP://{0}” -f $_.Path)
$CreateOU = $OU.Create(“OrganizationalUnit”,(“OU={0}” -f $_.Name))
$CreateOU.SetInfo()

}

I did not test the above code, so be sure to test the code prior to running against an entire CSV by just running the bolded code with static values.


Viewing all articles
Browse latest Browse all 13067

Trending Articles