-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddOrganizationAd.ps1
More file actions
54 lines (37 loc) · 1.26 KB
/
Copy pathAddOrganizationAd.ps1
File metadata and controls
54 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function New-ADOrganizationalUnitCsv{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[String]$OUPrincipal,
[Parameter(Mandatory=$true)]
[String]$CsvPath
)
$CsvGroup = Import-Csv $CsvPath -Delimiter ","
$DistinguishedName = (Get-AdDomain).DistinguishedName
foreach ($OU in $OUPrincipal) {
$list = @{
Name = $OU
path = $DistinguishedName
ProtectedFromAccidentalDeletion = $false
}
$Exist = Get-ADOrganizationalUnit -Filter "Name -like '$OU'" -ErrorAction SilentlyContinue
if ($Exist){
Write-Host "This Organization $OU already exist " -Foreground Yellow
}else{
New-ADOrganizationalUnit @list
Write-Host "Success Creation of $OU" -ForegroundColor Green
Get-ADOrganizationalUnit -Filter "Name -like '$OU'"
}
foreach ($SubOu in $CsvGroup) {
$path = "OU=$OU,$DistinguishedName"
$NameSubOrganizationunit = $SubOu.OU
$Sub = @{
Name = $NameSubOrganizationunit
Path = $path
ProtectedFromAccidentalDeletion = $false
}
New-ADOrganizationalUnit @Sub
Write-Host "Success Creation of $NameSubOrganizationunit under Principal Organization Unit $OU" -ForegroundColor Green
}
}
}