-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-funcs.ps1
More file actions
94 lines (78 loc) · 3.41 KB
/
test-funcs.ps1
File metadata and controls
94 lines (78 loc) · 3.41 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# STATIC VARS
$modelPath = ".\model.json"
$model = Get-Content $modelPath | ConvertFrom-Json
# VARS
$domain = (Get-ADDomain).Forest
$domainDN = (Get-ADRootDSE).rootDomainNamingContext
# FUNCTIONS
<#
.SYNOPSIS
Create new OUs and subOUs(if any)
.DESCRIPTION
Create new OUs and subOUs from the .json input in the $ParentOU
.PARAMETER ParentOU
Distinguished name of the parent OU where the OU and subOUs will be created
.PARAMETER model_in
Imported data from a .json with at least an "OUName" key value in it.
.PARAMETER Protected
boolean to set "ProtectedFromAccidentalDeletion" when creating the OU/subOUs
.PARAMETER Custom
Switch to use when there are more than one OU/subOUs in the $model_in, OU name key should match "CustomNameX" and subOUs array key should match "subOUsX" (where x begin at 1)
.EXAMPLE
New-OUsGeneration -ParentOU "OU=_ROOT,DC=testdom,DC=local" -model_in ($model.SecGroupsOUs)
New-OUsGeneration -ParentOU "OU=_ROOT,DC=testdom,DC=local" -model_in ($model.CustomOUs) -Custom
#>
function New-OUsGeneration{
param (
$ParentOU,
$model_in,
[bool]$Protected,
[switch]$Custom
)
if (!$Custom){
New-ADOrganizationalUnit -Name $model_in.OUName -Path $ParentOU -ProtectedFromAccidentalDeletion $Protected
$OUdn = (Get-ADOrganizationalUnit -Filter * | Where-Object Name -eq $model_in.OUName).DistinguishedName
write-host "[+] $($model_in.OUName)" -ForegroundColor Yellow
foreach ($subOU in $model_in.subOUS){
New-ADOrganizationalUnit -Name $subOU -Path $OUdn -ProtectedFromAccidentalDeletion $Protected
Write-Host " [+] $subOU" -ForegroundColor Yellow
}
}
else {
# process looping throug each CustomNameX
$index = 1
while ($true) {
$ouNameIter = "CustomName$index"
$subOUsIter = "subOUs$index"
if ($model_in.PSObject.Properties.Name -contains $ouNameIter) {
$ouName = $model_in.$ouNameIter
$subOUs = $model_in.$subOUsIter
New-ADOrganizationalUnit -Name $ouName -Path $ParentOU -ProtectedFromAccidentalDeletion $Protected
$OUdn = (Get-ADOrganizationalUnit -Filter * | Where-Object Name -eq $ouName).DistinguishedName
Write-Host "[+] $ouName"
foreach ($subOU in $subOUs) {
New-ADOrganizationalUnit -Name $subOU -Path $OUdn -ProtectedFromAccidentalDeletion $Protected
Write-Host " [+] $subOU"
}
}
else {break}
$index++
}
}
}
New-ADOrganizationalUnit -Name $model.RootOUName -Path $domainDN -ProtectedFromAccidentalDeletion $model.PreventOUDeletion
$RootOUdn = (Get-ADOrganizationalUnit -Filter * | Where-Object Name -eq $model.RootOUName).DistinguishedName
Write-Host "[+] $($model.RootOUName)" -ForegroundColor Green
New-OUsGeneration -ParentOU $RootOUdn -model_in ($model.UsersBaseOU) -Protected $model.PreventOUDeletion
New-OUsGeneration -ParentOU $RootOUdn -model_in ($model.ComputersOUs) -Protected $model.PreventOUDeletion
New-OUsGeneration -ParentOU $RootOUdn -model_in ($model.SecGroupsOUs) -Protected $model.PreventOUDeletion
New-OUsGeneration -ParentOU $RootOUdn -model_in ($model.CustomOUs) -Protected $model.PreventOUDeletion -Custom
#----------------------
# Struct
# install-adds
#Create defined OUs
# Depts
## Create-OU
## Create-SecGroups
## Add-members
## Create-FileShare