I have this notepad ++ file:
OU=AAA,OU=111,OU=LOCATION,DC=corp,DC=local OU=BBB,OU=222,OU=LOCATION,DC=corp,DC=local OU=BBB,OU=333,OU=LOCATION,DC=corp,DC=local . . . <250 more unique lines)
and this script:
param([parameter(Mandatory=$true)] [String]$FileCSV)
$listOU=Import-CSV $FileCSV -Delimiter ";"
ForEach($OU in $listOU){
try{
#Get Name and Path from the source file
$OUName = $OU.Name
$OUPath = $OU.Path
#Display the name and path of the new OU
Write-Host -Foregroundcolor Yellow $OUName $OUPath
#Create OU
New-ADOrganizationalUnit -Name "$OUName" -Path "$OUPath"
#Display confirmation
Write-Host -ForegroundColor Green "OU $OUName created"
}catch{
Write-Host $error[0].Exception.Message
}
}
which is reading this csv:
name;path Groups;OU=AAA,OU=111,OU=LOCATION,DC=corp,DC=local Servers;OU=AAA,OU=111,OU=LOCATION,DC=corp,DC=local Users;OU=AAA,OU=111,OU=LOCATION,DC=corp,DC=local Workstations;OU=AAA,OU=111,OU=LOCATION,DC=corp,DC=local
…and realizing this is still gonna take a lot of manual work.
Is there a way to either massage the notepad ++ file to create the required (4) sub-OUs for all those Parent OUs in the first list?
thank you