forked from cfalta/adsec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomainprepare.ps1
54 lines (48 loc) · 1.64 KB
/
domainprepare.ps1
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
if(Test-Path .\domainprepare.json)
{
$config = cat .\domainprepare.json | convertfrom-json
if($config)
{
Import-Module ActiveDirectory
$DomainRoot = (Get-ADDomain).distinguishedname
$DNSRoot = (get-addomain).DNSRoot
foreach($ou in $config.ou)
{
if($ou.DistinguishedName)
{
$oupath = $ou.DistinguishedName + ","+ $DomainRoot
}
else
{
$oupath = $DomainRoot
}
New-ADOrganizationalUnit -Name $ou.name -Path $oupath
}
foreach($user in $config.user)
{
$upn = $user.UserPrincipalName + "@" + $DNSRoot
$securePassword = ConvertTo-SecureString $user.Password -AsPlainText -force
New-ADUser -Name $user.name -SamAccountName $user.samAccountName -DisplayName $user.DisplayName -UserPrincipalName $upn -AccountPassword $securePassword -Enabled $true -Path ($user.OU + "," + $DomainRoot) -PasswordNeverExpires $true
}
foreach($group in $config.GroupAdd)
{
if($group.ou)
{
$oupath = $group.ou + ","+ $DomainRoot
}
else
{
$oupath = $DomainRoot
}
New-ADGroup -Name $group.Name -GroupScope $group.scope -GroupCategory $group.category -Description $group.description -Path $oupath
}
foreach($group in $config.GroupMember)
{
Add-ADGroupMember -Identity $group.group -Members $group.member
}
foreach($e in $config.execute)
{
$e.cmd | iex
}
}
}