-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathadds_install.ps1
More file actions
60 lines (55 loc) · 2.16 KB
/
adds_install.ps1
File metadata and controls
60 lines (55 loc) · 2.16 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
<#
.SYNOPSIS
Setting the right parameters for setting up the AD DS.
.PARAMETER DomainName
The fully qualified domain name (FQDN) of the new domain.
.PARAMETER DomainNetBIOSName
The NetBIOS name of the new domain.
.PARAMETER Username
The username of an account with sufficient privileges to add a new domain.
.PARAMETER Password
The password of the account specified in the Username parameter.
.EXAMPLE
.\adds_install.ps1 -DomainName "VM.contoso.com" -DomainNetBIOSName "contoso" -Username "bob" -Password "P@ssw0rd1"
#>
Param(
[Parameter(Mandatory = $true)]
[string]$DomainName,
[Parameter(Mandatory = $true)]
[string]$DomainNetBIOSName,
[Parameter(Mandatory = $true)]
[string]$Username,
[Parameter(Mandatory = $true)]
[String]$Password
)
<#
.SYNOPSIS
Main function that installs and sets up ADDS on a server.
.DESCRIPTION
This function installs the Active Directory module and sets up ADDS on a server.
.INPUTS
None
.PARAMETER None
.EXAMPLE
Install-ADDS
#>
function Install-ADDS {
if ((Get-WindowsFeature -Name AD-Domain-Services).Installed) {
try {
Get-ADUser -Identity $Username
Write-Host "[Install-ADDS] User $Username exists."
}
catch {
# Create a new user
New-ADUser -Name $Username -AccountPassword (ConvertTo-SecureString -String $Password -AsPlainText -Force) -Enabled $true -ChangePasswordAtLogon $false
Write-Host "[New-ADDS] A new user has been created."
}
}
else {
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools -Restart:$false -Confirm:$false
Write-Host "[Install-ADModules] Active Directory module has been installed."
Install-ADDSForest -DomainName $DomainName -DomainNetBIOSName $DomainNetBIOSName -SafeModeAdministratorPassword (ConvertTo-SecureString -String $Password -AsPlainText -Force) -SkipPreChecks -NoRebootOnCompletion:$true -Force:$true -SkipAutoConfigureDns:$true
Write-Host "[Install-ADDS] Server has been promoted to domain controller. The server must be restarted before the Active Directory module can be used."
}
}
Install-ADDS