Overblog
Editer l'article Suivre ce blog Administration + Créer mon blog

Install New AD from Powershell

Publié le par damcuvelier

Semi-Automatique Install New AD from Powershell:

AddAdPrereqs.ps1 (need reboot after because of the computer rename):

Param(
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$ipaddress = "192.168.0.255",
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$netbiosName = "24",
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$ipgw = "192.168.0.1", # gateway
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$ipdns = "192.168.0.2", # dns @ip
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$dcname = "newdomaineDC" #name of DC
)
$ipif = (Get-NetAdapter).ifIndex
#set static IP address
New-NetIPAddress -IPAddress $ipaddress -PrefixLength $ipprefix -InterfaceIndex $ipif -DefaultGateway $ipgw

#rename the computer
Rename-Computer -NewName $dcname -force

#install features
$featureLogPath = "c:\poshlog\featurelog.txt"
New-Item $featureLogPath -ItemType file -Force
$addsTools = "RSAT-AD-Tools"
Add-WindowsFeature $addsTools
Get-WindowsFeature | Where installed >>$featureLogPath

#restart the computer
Restart-Computer

 

Add-ADFeatures_and_InstallNewForest.ps1 (install the necessary Features for the basic installation of a forest, then Create New Forest and add Domain Controller):

Param(
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$domainname = "newdomaine.com", #FQDN name of the new domain
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$netbiosName = "newdomaine", #netbios name of the new domain (exl: "newdomaine")
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$domMode = "WinThreshold", #mode of the domain installation ("WinThreshold" for Win2016) (*)
    [Parameter(Mandatory=$false, ValueFromPipeline=$true)][string[]]$forMode = "Win2012R2" #mode of the forest installation
)

    #Install AD DS, DNS and GPMC
    $featureLogPath = "c:\poshlog\featurelog.txt"
    start-job -Name addFeature -ScriptBlock {
    Add-WindowsFeature -Name "ad-domain-services" -IncludeAllSubFeature -IncludeManagementTools
    Add-WindowsFeature -Name "dns" -IncludeAllSubFeature -IncludeManagementTools
    Add-WindowsFeature -Name "gpmc" -IncludeAllSubFeature -IncludeManagementTools }
    Wait-Job -Name addFeature
    Get-WindowsFeature | Where installed >>$featureLogPath

    Import-Module ADDSDeployment
    Install-ADDSForest -CreateDnsDelegation:$false -DatabasePath "C:\Windows\NTDS" -DomainMode $domMode -DomainName $domainname -DomainNetbiosName $netbiosName -ForestMode $forMode -InstallDns:$true -LogPath "C:\Windows\NTDS" -NoRebootOnCompletion:$false -SysvolPath "C:\Windows\SYSVOL" -Force:$true

(*):
The domain functional level cannot be lower than the forest functional level, but it can be higher. The default is automatically computed and set.
So for a mixed mode, use "Win2012R2" for the ForestMode and "WinThreshold" (for Win2016) for the DomainMode.
ForestMode/DomainMode:
    Windows Server 2003: 2 or Win2003
    Windows Server 2008: 3 or Win2008
    Windows Server 2008 R2: 4 or Win2008R2
    Windows Server 2012: 5 or Win2012
    Windows Server 2012 R2: 6 or Win2012R2
    Windows Server 2016: 7 or WinThreshold

 

Commenter cet article