PowerShell Script To Create New Organizational Units From A Text File

 

This PowerShell script which is similar to my previous post entitled PowerShell Script To Create A New Organizational Unit will allow you to create new multiple Organizational Units (OU’s) based on names taken from a text file called NewOus.Txt rather than entering the new OU names one at a time.

 

Note: Be sure to change MyDomainName to your domain name and change Com if needed to reflect your sites naming.

 

PS1 Script:

 

$TextFile = GC -Path "C:\NewOus.Txt"

ForEach ($objItem in $TextFile){

$StrOUName = $objItem

 

$objDomain = [ADSI]"LDAP://dc= MyDomainName,dc=Com"

$objOU = $objDomain.Create("OrganizationalUnit", "ou=" + $StrOUName)

$objOU.setInfo()}

 

Write-Host "Your New OU's Have Been Created"

 

Published Sunday, September 30, 2007 7:23 AM by dhite
Filed under:

Comments

No Comments