$OUName=read-host “Please enter the OU name you wish to create”
$objUser = [ADSI]“LDAP://localhost:389/dc=contoso,dc=com”
$ou=$objUser.create(“organizationalunit”, “ou=$OUName”)
$ou.setinfo()
# ============================
$date=get-date
$futdate=$date.addseconds(5)
$towait=$futdate – $date
$waittime=$towait.seconds
while($waittime -gt 0) {
$waittime=$waittime-1
write-host “Warning: Operation is in progress …” -foreground yellow
start-sleep -s 1
if($waittime -le 0) {
$OUcreated=[ADSI]“LDAP://localhost:389/ou=$OUname,dc=contoso,dc=com”
If($OUcreated.true){
Write-host $OUname OU is created successfully -ForegroundColor “Green”
}
}
}