-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBiuld_ADC_iac.ps1
More file actions
89 lines (68 loc) · 3.51 KB
/
Copy pathBiuld_ADC_iac.ps1
File metadata and controls
89 lines (68 loc) · 3.51 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
$VerbosePreference = "Continue"
$dateformat = Get-Date -format 'MM.dd.yyyy.HH.mm.ss'
# Define the path of the folder you want to create
$LoggingDirectory = "C:\DCBuild"
# Check if the folder exists
if (-Not (Test-Path -Path $LoggingDirectory)) {
# Create the folder if it doesn't exist
New-Item -ItemType Directory -Path $LoggingDirectory
Write-Output "Folder created: $LoggingDirectory"
}
else {
Write-Output "Folder already exists: $LoggingDirectory"
}
$Logpath = "$($LoggingDirectory)\DC_Built_iac_($env:COMPUTERNAME)_$($dateformat).log"
Start-Transcript -Path $Logpath -Force
$getifmsrv = Read-Host "Please Enter The Nearest Domain Controller Name"
Invoke-Command -ComputerName $getifmsrv -ScriptBlock {
$IFMPATH = "C:\IFM"
If ((Test-Path -Path $IFMPATH) -eq $true) {
$Folders = Get-Childitem $IFMPATH -Recurse | Where-Object { $_.PsContainer -eq $True }
$Folders | ForEach-Object {
$strName = $_.Fullname
$acl = get-acl $strName
$acl.SetAccessRuleProtection($false, $false)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators", "Full", "ContainerInherit,ObjectInherit", "NoPropagateInherit", "Allow")
$acl.AddAccessrule($rule)
set-acl $strName $acl
}
Remove-item $IFMPATH -Force -Recurse -Verbose
Write-Host "Old IFM Removed Successfully" -ForegroundColor Green -BackgroundColor DarkMagenta
Start-Sleep -Seconds 5
}
@"
..................................................................
..................................................................
................. CODE TO CREATE IFM FILES .....................
..................................................................
..................................................................
Process is about to start .......................................
This Process can take about 15 minutes...........................
The IFM Files will be stored on ........... $IFMPATH
"@
$IFM = ntdsutil "activate instance ntds" IFM "create full $IFMPath" q q q
@"
..................................................................
..................................................................
................ IFM FILES CREATION COMPLETED ...................
..................................................................
..................................................................
Output of IFM Opertaion ..........................................
"@
$IFM
IF ($IFM -like "*IFM media created successfully*") {
Write-Host "IFM Code Successfully Created the IFM Media Set" `r -ForegroundColor Green
$Success = "True"
}
}
Start-Sleep -Seconds 15
#Copy IFM to Local Server
Net use Z: \\$getifmsrv\c$\IFM
Robocopy Z: C:\IFM /copyall /s
Start-Sleep -Seconds 5
#Intall Prereqs
Add-WindowsFeature AD-Domain-Services, RSAT-ADDS, RSAT-ADDS-Tools, RSAT-AD-AdminCenter, RSAT-AD-PowerShell, RSAT-DNS-Server, RSAT-ADLDS, SNMP-Service, SNMP-WMI-Provider -Verbose
Start-Sleep -Seconds 5
#Promote Domain Controllers
Install-ADDSDomainController -CreateDnsDelegation:$false -DatabasePath 'C:\Windows\NTDS' -DomainName $env:USERDNSDOMAIN -InstallDns:$true -LogPath 'C:\Windows\NTDS' -NoGlobalCatalog:$false -SysvolPath 'C:\Windows\SYSVOL' -InstallationMediaPath 'C:\IFM' -NoRebootOnCompletion:$true -Force:$true
Stop-Transcript