forked from DeploymentResearch/HydrationKitWS2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomizeHydrationKit.ps1
246 lines (194 loc) · 14.5 KB
/
CustomizeHydrationKit.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<#
.Synopsis
Script to Customize Johan Arwidmarks Hydration kit for ConfigMgr
.DESCRIPTION
Created: 2017-04-31
Updated: 2023-07-31
Version: 2.0
- Rewritten to be run on the DeploymentShare
- Updated for WS2022 Hydration Kit
- Creates a backup of all changed files (.org) and can be rerun if wanted.
NOTE!! When rerun it will restore the original file before applying changes again and any manual changes on affected files will be lost!!
Changelog:
- Edited by Andrew Johnson (@andrewjnet) to include:
- Client sequence customization
- Active Directory user/OU customization
Author : Matt Benninge
Twitter: @matbg
Disclaimer: This script is provided "AS IS" with no warranties, confers no rights and
is not supported by the author or DeploymentArtist..
This version is only tested with the following Hydration Kit:
https://github.com/DeploymentResearch/HydrationKitWS2022
This should be used after the deployementshare has been created and on the deploymentshare created.
Uncomment any value that you do not whish to be customized and that value will be skipped.
.EXAMPLE
NA
#>
#Requires -RunAsAdministrator
#Requires -Version 3
#Set the path to the created deploymentshare
$HydrationSource = "D:\CMLab"
#Change Domain and OU structure, these values will be changed in all files where applicable
$NewDomainName = "corp.mydomain.org" #Default = corp.viamonstra.com
$NewDomainRoot = "dc=corp,dc=mydomain,dc=org"
$NewMachineOU = "ou=Servers,ou=MyDomain,dc=corp,dc=mydomain,dc=org" #Default = ou=Servers,ou=ViaMonstra,dc=corp,dc=viamonstra,dc=com
$NewOrgName = "MyDomain" #Default = ViaMonstra or VIAMONSTRA
$NewTimeZoneName = "W. Europe Standard Time" #Default = Pacific Standard Time
#Change Admin Passwd
# $NewPasswd = "newpass" #Default = P@ssw0rd
#General IP settings, used in all files where applicable, default for all these are on the 192.168.25.x net
$NewOSDAdapter0DNSServerList = "10.10.5.200" #Also used for DC01 ip-adress
$newOSDAdapter0Gateways= "10.10.5.1"
$NewOSDAdapter0SubnetMask= "255.255.255.0"
$NewADSubNet = "10.10.5.0"
#DC01 - set DHCP scope on DC01
$NewDHCPScopes0StartIP="10.10.5.100"
$NewDHCPScopes0EndIP="10.10.5.199"
#Set IP-adress for CM01
$NewCM01OSDAdapter0IPAddressList= "10.10.5.214"
#Set IP-adress for DP01
$NewDP01OSDAdapter0IPAddressList= "10.10.5.245"
#Set IP-adress for MDT01
$NewMDT01OSDAdapter0IPAddressList= "10.10.5.210"
#Set IP-adress for FS01
$NewFS01OSDAdapter0IPAddressList= "10.10.5.213"
#Set IP-adress for PC0001
$NewPC0001OSDAdapter0IPAddressList= "10.10.5.11"
#Set IP-adress for PC0002
$NewPC0002OSDAdapter0IPAddressList= "10.10.5.12"
#Set IP-adress for PC0003
$NewPC0003OSDAdapter0IPAddressList= "10.10.5.13"
#Set IP-adress for PC0004
$NewPC0004OSDAdapter0IPAddressList= "10.10.5.14"
#------------------ Do Not change below this line-----------------#
$ResultList = $null
$ResultList = [System.Collections.Generic.List[object]]::new()
Function Update-HKContent {
param(
[string]$fileName,
[string]$orgValue,
[string]$newValue,
[switch]$ToUpper
)
$Properties = [ordered]@{
OrgValue = $orgValue
NewValue = $newValue
Filename = $fileName
}
if(test-path $fileName) {
if (test-path "$fileName.org") {
Write-Debug "$fileName already has an org backup"
$content = Get-Content "$fileName"
} else {
Write-Debug "Creating a copy of original file in $filename.org"
Copy-Item $fileName "$fileName.org"
$content = Get-Content "$fileName"
}
if($ToUpper) {
$content.Replace($orgValue,$newValue.ToUpper()) | Set-Content $fileName
$Properties.NewValue = $newValue.ToUpper()
} else {
$content.Replace($orgValue,$newValue) | Set-Content $fileName
}
$ResultList.Add((New-Object PsObject -Property $Properties))
} else {
Write-Warning "$filename not found, skipping!"
}
}
function Update-HKContentRecurse {
param(
$SourceFiles,
[string]$pattern,
[string]$newValue,
[switch]$ToUpper
)
$foundFiles = $SourceFiles | Select-String -pattern $pattern | Group-Object path | Select-Object name
foreach($file in $foundFiles)
{
Update-HKContent -fileName $file.Name -orgValue $pattern -newValue $newValue -ToUpper:$ToUpper
}
}
#restore original files if previously edited
$orgFiles = Get-ChildItem -recurse -Path $HydrationSource\ISO -Include ("*.org")
$orgFiles += Get-ChildItem -recurse -Path $HydrationSource\DS -Include ("*.org")
if($orgFiles)
{
foreach($orgFile in $orgFiles)
{
$fileName = $orgFile.FullName -replace "$([System.IO.Path]::GetFileNameWithoutExtension($orgFile.FullName)).org","$([System.IO.Path]::GetFileNameWithoutExtension($orgFile.FullName))"
Copy-Item $orgFile.FullName $fileName -force
}
}
#Update CreateHydrationDeploymentShare.ps1
#If($NewMDTPath){(Update-HKContent -fileName $HydrationSource\Source\CreateHydrationDeploymentShare.ps1 -orgValue 'C:' -newValue $NewMDTPath) | Set-Content $HydrationSource\Source\CreateHydrationDeploymentShare.ps1}
#Update Customsettings.ini
If($NewTimeZoneName){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\CustomSettings.ini -orgValue 'Pacific Standard Time' -newValue $NewTimeZoneName}
#Update Customsettings_CM01.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_CM01.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_CM01.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewCM01OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_CM01.ini -orgValue '192.168.25.214' -newValue $NewCM01OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_CM01.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_DC01.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DC01.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DC01.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DC01.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
If($NewADSubNet){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DC01.ini -orgValue '192.168.25.0' -newValue $NewADSubNet }
If($NewDHCPScopes0StartIP){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DC01.ini -orgValue '192.168.25.100' -newValue $NewDHCPScopes0StartIP }
If($NewDHCPScopes0EndIP){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DC01.ini -orgValue '192.168.25.199' -newValue $NewDHCPScopes0EndIP }
#Update Customsettings_MDT01.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_MDT01.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_MDT01.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewMDT01OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_MDT01.ini -orgValue '192.168.25.210' -newValue $NewMDT01OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_MDT01.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_DP01.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DP01.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DP01.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewDP01OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DP01.ini -orgValue '192.168.25.245' -newValue $NewDP01OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_DP01.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_FS01.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_FS01.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_FS01.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewFS01OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_FS01.ini -orgValue '192.168.25.213' -newValue $NewFS01OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_FS01.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_PC0001.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0001.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0001.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewPC0001OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0001.ini -orgValue '192.168.25.11' -newValue $NewPC0001OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0001.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_PC0002.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0002.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0002.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewPC0002OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0002.ini -orgValue '192.168.25.12' -newValue $NewPC0002OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0002.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_PC0003.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0003.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0003.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewPC0003OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0003.ini -orgValue '192.168.25.13' -newValue $NewPC0003OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0003.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Customsettings_PC0004.ini
If($NewOSDAdapter0DNSServerList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0004.ini -orgValue '192.168.25.200' -newValue $NewOSDAdapter0DNSServerList }
If($newOSDAdapter0Gateways){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0004.ini -orgValue '192.168.25.1' -newValue $newOSDAdapter0Gateways }
If($NewPC0004OSDAdapter0IPAddressList){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0004.ini -orgValue '192.168.25.14' -newValue $NewPC0004OSDAdapter0IPAddressList }
If($NewOSDAdapter0SubnetMask){Update-HKContent -fileName $HydrationSource\ISO\Content\Deploy\Control\Customsettings_PC0004.ini -orgValue '255.255.255.0' -newValue $NewOSDAdapter0SubnetMask }
#Update Scripts
If($NewADSubNet){Update-HKContent -fileName "$($HydrationSource)\ISO\Content\Deploy\Applications\Configure - Create AD Subnets\Configure-CreateADSubnets.ps1" -orgValue '192.168.25.0' -newValue $NewADSubNet }
$sourceFiles = Get-ChildItem -recurse -Path "$HydrationSource\ISO" -Include ("*.ini","*.ps1","*.vbs","*.wsf","*.xml","*.csv")
$sourceFiles += Get-ChildItem -recurse -Path "$HydrationSource\DS" -Include ("*.ini","*.ps1","*.vbs","*.wsf","*.xml","*.csv")
# $sourceFiles | Select-String -Pattern 'VIAMONSTRA'
#Update Domain Name
If($NewMachineOU) { Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'ou=Servers,ou=ViaMonstra,dc=corp,dc=viamonstra,dc=com' -NewValue $NewMachineOU }
#Update Domain Name
If($NewDomainName) { Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'corp.viamonstra.com' -NewValue $NewDomainName }
#Update Domain Root
If($NewDomainRoot) { Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'dc=corp,dc=viamonstra,dc=com' -NewValue $NewDomainRoot }
If($NewDomainRoot) { Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'DC=corp,DC=viamonstra,DC=com' -NewValue $NewDomainRoot }
#Update ORGName
If($NewOrgName) {
Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'ViaMonstra' -NewValue $NewOrgName
Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'VIAMONSTRA' -NewValue $NewOrgName -ToUpper
}
#Update password
If($NewPasswd) { Update-HKContentRecurse -SourceFiles $sourceFiles -pattern 'P@ssw0rd' -NewValue $NewPasswd }
Write-Host "The following changes have been done:"
$ResultList | Sort-Object -Property FileName |Format-Table
Write-host -ForegroundColor Yellow "Update your boot ISO MEDIA001 for the changes to take effect!"