Komplett MDT konfiguration med powershell

Till er som saknat ett powershellscript för att sätta upp alla grundkonfiguration i MDT ink. databaskoppling!
Scriptet förutsätter att man har installerat ADK 8.1 och MDT först.

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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<#
 #############################################################################
 #  Created:	2014-01-01
 #  version:	v1.1
 #  Author:	Henrik Toft
 #  Homepage:	http://www.toft.se/
 #  Disclaimer:	This script is provided "AS IS" with no warranties
 #############################################################################
#>
 
## Vars
$SQLServer = "LAB-MDT01"
$SQLInstance = "ADK"
$SQLDatabase = "MDT"
$Netlib = "DBNMPNTW"
$MDTShareName = "DS01"
$MDTRoot = "C:\MDT\DS01"
$WDSRoot = "C:\WDS"
$ISORoot = "C:\ISOS"
$MDTShare = "\\LAB-MDT01\DS01"
$CSPath = "$MDTRoot\Control\CustomSettings.ini"
$BSPath = "$MDTRoot\Control\Bootstrap.ini"
$DSDescription = "DS01 - LabProduction"
$DomainName = "LAB"
$DomainUser = "Administrator"
$DomainPassword = "P@ssw0rd"
 
 
## Import MDT Module
Import-Module "C:\Program Files\Microsoft Deployment Toolkit\bin\MicrosoftDeploymentToolkit.psd1"
 
## Setup Directories
New-Item -Type Directory $MDTRoot
New-Item -Type Directory $WDSRoot
New-Item -Type Directory $ISORoot
 
# Share DS
New-SmbShare -Path $MDTRoot -Name $MDTShareName -ReadAccess Everyone
 
## Setup DeploymentShare DS01
New-PSDrive -Name "DS001" -PSProvider "MDTProvider" -Root $MDTRoot -Description $DSDescription -NetworkPath $MDTShare -Verbose | add-MDTPersistentDrive -Verbose
 
## Build CustomSettings.ini for LAB-MDT01
Function Build-CustomSettings {
 
if (Test-path $CSPath) {Remove-Item -Path $CSPath -Force}
New-Item -Path $CSPath -type file
 
Add-Content -path $CSPath -value  "[Settings]"
Add-Content -path $CSPath -value  "Priority=CSettings, CPackages, CApps, CAdmins, CRoles, Locations, LSettings, LPackages, LApps, LAdmins, LRoles, MMSettings, MMPackages, MMApps, MMAdmins, MMRoles, RSettings, RPackages, RApps, RAdmins, Default"
Add-Content -path $CSPath -value  "Properties=MyCustomProperty"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[Default]"
Add-Content -path $CSPath -value  "OSInstall=YES"
Add-Content -path $CSPath -value  "SkipBDDWelcome=YES"
Add-Content -path $CSPath -value  "SkipCapture=NO"
Add-Content -path $CSPath -value  "SkipAdminPassword=YES"
Add-Content -path $CSPath -value  "SkipApplications=YES"
Add-Content -path $CSPath -value  "SkipAppsOnUpgrade=YES"
Add-Content -path $CSPath -value  "SkipProductKey=YES"
Add-Content -path $CSPath -value  "SkipDomainMembership=YES"
Add-Content -path $CSPath -value  "SkipComputerName=YES"
Add-Content -path $CSPath -value  "SkipUserData=YES"
Add-Content -path $CSPath -value  "SkipTaskSequence=NO"
Add-Content -path $CSPath -value  "SkipLocaleSelection=YES"
Add-Content -path $CSPath -value  "SkipSummary=YES"
Add-Content -path $CSPath -value  "SkipBitLocker=YES"
Add-Content -path $CSPath -value  "KeyboardLocale=sv-SE"
Add-Content -path $CSPath -value  "UserLocale=sv-SE"
Add-Content -path $CSPath -value  "UILanguage=sv-SE"
Add-Content -path $CSPath -value  "SkipTimeZone=YES"
Add-Content -path $CSPath -value  "TimeZoneName=W. Europe Standard Time"
Add-Content -path $CSPath -value  "HideShell=NO"
Add-Content -path $CSPath -value  "ApplyGPOPack=NO"
Add-Content -path $CSPath -value  "DomainAdmin=Administrator"
Add-Content -path $CSPath -value  "DomainAdminDomain=lab"
Add-Content -path $CSPath -value  "DomainAdminPassword=P@ssw0rd"
Add-Content -path $CSPath -value  "JoinDomain=lab.labben.se"
Add-Content -path $CSPath -value  "MachineObjectOU=OU=LabServers,OU=MACHINES,OU=LAB,DC=lab,DC=labben,DC=se"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerSettings"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerPackages"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerApplications"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerAdministrators"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[CRoles]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=ComputerRoles"
Add-Content -path $CSPath -value  "Parameters=UUID, AssetTag, SerialNumber, MacAddress"
Add-Content -path $CSPath -value  "ParameterCondition=OR"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[Locations]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=Locations"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationSettings"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationPackages"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationApplications"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationAdministrators"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[LRoles]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=LocationRoles"
Add-Content -path $CSPath -value  "Parameters=DefaultGateway"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelSettings"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelPackages"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelApplications"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelAdministrators"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[MMRoles]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=MakeModelRoles"
Add-Content -path $CSPath -value  "Parameters=Make, Model"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RSettings]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RoleSettings"
Add-Content -path $CSPath -value  "Parameters=Role"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RPackages]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RolePackages"
Add-Content -path $CSPath -value  "Parameters=Role"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RApps]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RoleApplications"
Add-Content -path $CSPath -value  "Parameters=Role"
Add-Content -path $CSPath -value  "Order=Sequence"
Add-Content -path $CSPath -value  "`r"
Add-Content -path $CSPath -value  "[RAdmins]"
Add-Content -path $CSPath -value  "SQLServer=$SQLServer"
Add-Content -path $CSPath -value  "Instance=$SQLInstance"
Add-Content -path $CSPath -value  "Database=$SQLDatabase"
Add-Content -path $CSPath -value  "Netlib=$Netlib"
Add-Content -path $CSPath -value  "SQLShare=$MDTShareName"
Add-Content -path $CSPath -value  "Table=RoleAdministrators"
Add-Content -path $CSPath -value  "Parameters=Role"
}
Build-CustomSettings
 
## Build Bootstrap.ini
Function Build-Bootstrap {
 
if (Test-path $BSPath) {Remove-Item -Path $BSPath -Force}
New-Item -Path $BSPath -type file
 
Add-Content -path $BSPath -value  "[Settings]"
Add-Content -path $BSPath -value  "Priority=Default"
Add-Content -path $BSPath -value  "`r"
Add-Content -path $BSPath -value  "[Default]"
Add-Content -path $BSPath -value  "DeployRoot=$MDTShare"
Add-Content -path $BSPath -value  "SkipBDDWelcome=YES"
Add-Content -path $BSPath -value  "UserDomain=$DomainName"
Add-Content -path $BSPath -value  "UserID=$DomainUser"
Add-Content -path $BSPath -value  "UserPassword=$DomainPassword"
}
Build-Bootstrap
 
## Configure SQL Server
$wmi = new-object ("Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer") "$env:computername"
 
# Enable the TCP protocol
$uri = "ManagedComputer[@Name='$env:computername']/ ServerInstance[@Name='$SQLInstance']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $true
$Tcp.Alter()
$Tcp
 
# Enable the Named Pipes protocol
$uri = "ManagedComputer[@Name='$env:computername']/ ServerInstance[@Name='$SQLInstance']/ServerProtocol[@Name='Np']"
$Np = $wmi.GetSmoObject($uri)
$Np.IsEnabled = $true
$Np.Alter()
$Np
 
# Enable SQL Browser
Get-Service SQLBrowser | Set-Service -StartupType Automatic -Verbose
Get-Service SQLBrowser | Start-Service -Verbose
 
# Configure Firewall
New-NetFirewallRule -Name "Allow SqlServr" -DisplayName "Allow SqlServr" -Program "C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.ADK\MSSQL\Binn\sqlservr.exe" -Enabled True -Profile Domain -Action Allow
New-NetFirewallRule -Name "Allow SqlBrowser" -DisplayName "Allow SqlBrowser" -Program "C:\Program Files (x86)\Microsoft SQL Server\90\Shared\sqlbrowser.exe" -Enabled True -Profile Domain -Action Allow
New-NetFirewallRule -Name "Allow SqlBrowser UDP 1434" -DisplayName "Allow SqlBrowser UDP 1434" -LocalPort 1434 -Protocol UDP -Action Allow -Profile Domain
 
## Setup MDT Database
New-MDTDatabase -path "DS001:" -SQLServer $SQLServer -Instance $SQLInstance -Netlib $Netlib -Database $SQLDatabase -SQLShare $MDTShareName -Verbose
 
## Build DS01
Update-MDTDeploymentShare -path "DS001:" -Verbose
 
## Configure WDS
if ($(Get-WindowsFeature WDS).InstallState -like "Available") {
    Write-Verbose "WDS Service is not installed. installing WDS..." -Verbose
    Install-WindowsFeature WDS -IncludeAllSubFeature -IncludeManagementTools -Verbose
    Write-Verbose "Server needs to reboot, reboot the server before running the script again" -Verbose
    break
    }
    elseif ($(Get-WindowsFeature WDS).InstallState -like "Installed") {
    Write-Verbose "WDS Service already installed. no need to install it" -Verbose
    }
    else {Write-Verbose "WDS Service state could not be determined" -Verbose}
 
Invoke-Expression "wdsutil /initialize-server /reminst:$WDSRoot"
Invoke-Expression "wdsutil /Set-Server /AnswerClients:all"
Invoke-Expression "wdsutil /Set-Server /pxepromptpolicy /known:noprompt"
Import-WdsBootImage -Path $MDTRoot\Boot\LiteTouchPE_x64.wim -NewImageName "LiteTouch x64" -SkipVerify
This entry was posted in Deployment, Powershell. Bookmark the permalink.

Kommentera

E-postadressen publiceras inte. Obligatoriska fält är märkta *

*


+ 7 = sexton

23 560 Spam Comments Blocked so far by Spam Free Wordpress

Följande HTML-taggar och attribut är tillåtna: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>