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

Assuming you have RSAT tools installed, you can use the AD module and do something like this:
# OU.csv
#
#”Name”,”Path”
#”MyNewOU1″, “DC=FABRIKAM,DC=COM”
#”MyNewOU2″, “DC=FABRIKAM,DC=COM”
#”MyNewOU3″, “DC=FABRIKAM,DC=COM”

Import-Module ActiveDirectory
Import-CSV C:\Users\rob\desktop\OU.csv | ForEach{
New-ADOrganizationalUnit -Name $_.Name -Path $_.Path -WhatIf
}

or simplify it further leveraging the values via pipeline, since the CSV has a “Name” and “Path” matching the switches you can just do this:

Import-CSV C:\Users\rob\desktop\OU.csv | New-ADOrganizationalUnit -WhatIf

either should produce this:

What if: Performing operation “New” on Target “OU=MyNewOU1,DC=FABRIKAM,DC=COM”.
What if: Performing operation “New” on Target “OU=MyNewOU2,DC=FABRIKAM,DC=COM”.
What if: Performing operation “New” on Target “OU=MyNewOU3,DC=FABRIKAM,DC=COM”.

You’ll just need to remove the -Whatif when you are ready to make the actual changes.


Viewing all articles
Browse latest Browse all 13067

Latest Images

Trending Articles



Latest Images