Examples/Deploy_MDT_Server.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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
<#
$Modules =
@(
    @{
        Name = "xSmbShare"
        RequiredVersion = "1.1.0.0"
    },
    @{
        Name = "cNtfsAccessControl"
        RequiredVersion = "1.3.0"
    }
)
ForEach ($Module in $Modules)
{
    If (-not((Get-DscResource -Module $Module.Name -Verbose:$False).Version -eq $Module.RequiredVersion ))
    {
        Install-Module -Name $Module.Name -RequiredVersion $Module.RequiredVersion
    }
     
}
#>


Function Get-ConfigurationDataAsObject
{
    [CmdletBinding()]
    [OutputType([hashtable])]
    Param (
        [Parameter(Mandatory)]
        [Microsoft.PowerShell.DesiredStateConfiguration.ArgumentToConfigurationDataTransformation()]
        [hashtable] $ConfigurationData    
    )
    return $ConfigurationData
}

Configuration DeployMDTServerContract
{
    Param(
        [PSCredential]
        $Credentials
    )

    #NOTE: Every Module must be constant, DSC Bug?!
    Import-DscResource â€“ModuleName PSDesiredStateConfiguration
    Import-DscResource -ModuleName xSmbShare -ModuleVersion 1.1.0.0
    Import-DscResource -ModuleName cNtfsAccessControl -ModuleVersion 1.3.0
    Import-DscResource -ModuleName cMDT -ModuleVersion 1.0.0.8

    node $AllNodes.Where{$_.Role -match "MDT Server"}.NodeName
    {

        $SecurePassword = ConvertTo-SecureString $Node.MDTLocalPassword -AsPlainText -Force
        $UserName       = $Node.MDTLocalAccount
        $Credentials    = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword

        [string]$separator = ""
        [bool]$weblink = $false
        If ($Node.SourcePath -like "*/*") { $weblink = $true }

        LocalConfigurationManager  
        {
            RebootNodeIfNeeded = $AllNodes.RebootNodeIfNeeded
            ConfigurationMode  = $AllNodes.ConfigurationMode   
        }

        $Prerequisites = @{}

        ForEach ($Prerequisite in $Node.MDTInstallationSoftware.Keys)   
        {
            $Prerequisites.Add($Prerequisite, $Node.MDTInstallationSoftware.$Prerequisite.SourcePath)
        }

        cMDTPreReqs MDTPreReqs
        {
            Ensure        = "Present"            
            DownloadPath  = $Node.TempLocation
            Prerequisites = $Prerequisites
        }

        User MDTAccessAccount
        {
            Ensure                 = "Present"
            UserName               = $Node.MDTLocalAccount
            FullName               = $Node.MDTLocalAccount
            Password               = $Credentials
            PasswordChangeRequired = $false
            PasswordNeverExpires   = $true
            Description            = "Managed Client Administrator Account"
            Disabled               = $false
        }

        WindowsFeature NET35
        {
            Ensure                 = "Present"
            Name                   = "Net-Framework-Core"
        }

        WindowsFeature WDS
        {
            Ensure                 = "Present"
            Name                   = "WDS"
            IncludeAllSubFeature   = $true
            LogPath                = "C:\Windows\debug\DSC_WindowsFeature_WindowsDeploymentServices.log"
        }

        cWDSConfiguration wdsConfig
        {
            Ensure                 = "Present"
            RemoteInstallPath      = "C:\RemoteInstall"
        }

        Package ADK
        {
            Ensure                 = $Node.MDTInstallationSoftware.ADK.Ensure
            Name                   = $Node.MDTInstallationSoftware.ADK.Name
            Path                   = "$($Node.TempLocation)\Windows Assessment and Deployment Kit\adksetup.exe"
            ProductId              = $Node.MDTInstallationSoftware.ADK.ProductId
            Arguments              = "/quiet /features OptionId.DeploymentTools OptionId.WindowsPreinstallationEnvironment"
            ReturnCode             = 0
        }

        Package MDT
        {
            Ensure                 = $Node.MDTInstallationSoftware.MDT.Ensure
            Name                   = $Node.MDTInstallationSoftware.MDT.Name
            Path                   = "$($Node.TempLocation)\Microsoft Deployment Toolkit\MicrosoftDeploymentToolkit2013_x64.msi"
            ProductId              = $Node.MDTInstallationSoftware.MDT.ProductId
            ReturnCode             = 0
        }

        Service WDSServer
        {
            Name                   = "WDSServer"
            State                  = "Running"
            StartUpType            = "Automatic"
            DependsOn              = "[WindowsFeature]WDS"
        }

        Service BITS
        {
            Name                   = "BITS"
            State                  = "Running"
            StartUpType            = "Automatic"
        }

        cMDTDirectory TempFolder
        {
            Ensure                 = "Present"
            Name                   = $Node.TempLocation.Replace("$($Node.TempLocation.Substring(0,2))\","")
            Path                   = $Node.TempLocation.Substring(0,2)
        }

        cMDTDirectory DeploymentFolder
        {
            Ensure                 = "Present"
            Name                   = $Node.PSDrivePath.Replace("$($Node.PSDrivePath.Substring(0,2))\","")
            Path                   = $Node.PSDrivePath.Substring(0,2)
            DependsOn              = "[Package]MDT"
        }

        xSmbShare FolderDeploymentShare
        {
            Ensure                 = "Present"
            Name                   = $Node.PSDriveShareName
            Path                   = $Node.PSDrivePath
            FullAccess             = "$env:COMPUTERNAME\$($Node.MDTLocalAccount)"
            FolderEnumerationMode  = "AccessBased"
            DependsOn              = "[cMDTDirectory]DeploymentFolder"
        }

        cNtfsPermissionEntry AssignPermissions
        {
            Ensure                     = "Present"
            Path                       = $Node.PSDrivePath
            Principal                  = "$env:COMPUTERNAME\$($Node.MDTLocalAccount)"
            AccessControlInformation   = @(
                cNtfsAccessControlInformation
                {
                    AccessControlType  = "Allow"
                    FileSystemRights   = "FullControl"
                    Inheritance        = "ThisFolderSubfoldersAndFiles"
                    NoPropagateInherit = $false
                }
            )
            DependsOn                  = "[cMDTDirectory]DeploymentFolder"
        }

        cMDTPersistentDrive DeploymentPSDrive
        {
            Ensure                 = "Present"
            Name                   = $Node.PSDriveName
            Path                   = $Node.PSDrivePath
            Description            = $Node.PSDrivePath.Replace("$($Node.PSDrivePath.Substring(0,2))\","")
            NetworkPath            = "\\$($env:COMPUTERNAME)\$($Node.PSDriveShareName)"
            DependsOn              = "[cMDTDirectory]DeploymentFolder"
        }

        ForEach ($SelectionProfile in $Node.SelectionProfiles)   
        {
            cMDTDirectory "SP$($SelectionProfile.Replace(' ',''))"
            {
                Ensure             = "Present"
                Name               = $SelectionProfile
                Path               = "$($Node.PSDriveName):\Selection Profiles"
                PSDriveName        = $Node.PSDriveName
                PSDrivePath        = $Node.PSDrivePath
                DependsOn          = "[cMDTDirectory]DeploymentFolder"
            }
        }

        ForEach ($OperatingSystem in $Node.OperatingSystems)   
        {

            [string]$SourcePath = $OperatingSystem.SourcePath
            If (-not(($SourcePath -like "*:*") -or ($SourcePath -like "*\\*")))
            {
                If ($weblink) { $SourcePath = "$($Node.SourcePath)$($SourcePath.Replace("\","/"))" }
                Else          { $SourcePath = "$($Node.SourcePath)$($SourcePath.Replace("/","\"))" }
            }

            cMDTOperatingSystem $OperatingSystem.Name.Replace(' ','')
            {
                Ensure            = $OperatingSystem.Ensure
                Name              = $OperatingSystem.Name
                Version           = $OperatingSystem.Version
                Path              = "$($Node.PSDriveName):$($OperatingSystem.Path)"
                SourcePath        = $SourcePath
                PSDriveName       = $Node.PSDriveName
                PSDrivePath       = $Node.PSDrivePath
                TempLocation      = $Node.TempLocation
                DependsOn         = "[cMDTDirectory]DeploymentFolder"
            }
        }

        ForEach ($TaskSequence in $Node.TaskSequences)   
        {

            If ($TaskSequence.WIMFileName)
            {
                cMDTTaskSequence $TaskSequence.Name.Replace(' ','')
                {
                    Ensure       = $TaskSequence.Ensure
                    Name         = $TaskSequence.Name
                    Path         = "$($Node.PSDriveName):$($TaskSequence.Path)"
                    WIMFileName  = $TaskSequence.WIMFileName
                    ID           = $TaskSequence.ID
                    PSDriveName  = $Node.PSDriveName
                    PSDrivePath  = $Node.PSDrivePath
                    DependsOn    = "[cMDTOperatingSystem]$($Node.OperatingSystems.Where{$_.SourcePath -like "*$($TaskSequence.WIMFileName)"}.Name.Replace(' ',''))"
                }
            }
            Else
            {
                cMDTTaskSequence $TaskSequence.Name.Replace(' ','')
                {
                    Ensure              = $TaskSequence.Ensure
                    Name                = $TaskSequence.Name
                    Path                = "$($Node.PSDriveName):$($TaskSequence.Path)"
                    OperatingSystemPath = "$($Node.PSDriveName):$($TaskSequence.OperatingSystemPath)"
                    ID                  = $TaskSequence.ID
                    PSDriveName         = $Node.PSDriveName
                    PSDrivePath         = $Node.PSDrivePath
                    DependsOn           = "[cMDTDirectory]DeploymentFolder"
                }

            }
        }

        foreach ($TaskSequenceSetVariableStep in $node.TaskSequenceSetVariableSteps)
        {
            
            $resourceName = "TS_VariableStep_$($TaskSequenceSetVariableStep.TaskSequenceId)-$($TaskSequenceSetVariableStep.TaskSequenceParentGroupName)-$($TaskSequenceSetVariableStep.InsertAfterStep)-$($TaskSequenceSetVariableStep.TaskSequenceStepName)"

            cMDT_TS_Step_SetVariable $resourceName.Replace(' ','')
            {
                Ensure                      = $TaskSequenceSetVariableStep.Ensure
                PSDrivePath                 = $Node.PSDrivePath
                TaskSequenceId              = $TaskSequenceSetVariableStep.TaskSequenceId
                TaskSequenceParentGroupName = $TaskSequenceSetVariableStep.TaskSequenceParentGroupName
                InsertAfterStep             = $TaskSequenceSetVariableStep.InsertAfterStep
                TaskSequenceVariableName    = $TaskSequenceSetVariableStep.TaskSequenceVariableName
                TaskSequenceVariableValue   = $TaskSequenceSetVariableStep.TaskSequenceVariableValue
                TaskSequenceStepName        = $TaskSequenceSetVariableStep.TaskSequenceStepName
                TaskSequenceStepDescription = $TaskSequenceSetVariableStep.TaskSequenceStepDescription
                Disable                     = $TaskSequenceSetVariableStep.Disable
                ContinueOnError             = $TaskSequenceSetVariableStep.ContinueOnError
                SuccessCodeList             = $TaskSequenceSetVariableStep.SuccessCodeList
                DependsOn                   = "[cMDTTaskSequence]$($Node.TaskSequences.Where{$_.Id -match $TaskSequenceSetVariableStep.TaskSequenceId}.Name.Replace(' ',''))"
            }
        }

        ForEach ($Driver in $Node.Drivers)   
        {

            [string]$SourcePath = $Driver.SourcePath
            If (-not(($SourcePath -like "*:*") -or ($SourcePath -like "*\\*")))
            {
                If ($weblink) { $SourcePath = "$($Node.SourcePath)$($SourcePath.Replace("\","/"))" }
                Else          { $SourcePath = "$($Node.SourcePath)$($SourcePath.Replace("/","\"))" }
            }

            cMDTDriver $Driver.Name.Replace(' ','')
            {
                Ensure                = $Driver.Ensure
                Name                  = $Driver.Name
                Version               = $Driver.Version
                Path                  = "$($Node.PSDriveName):$($Driver.Path)"
                SourcePath            = $SourcePath
                Comment               = $Driver.Comment
                Enabled               = "True"
                PSDriveName           = $Node.PSDriveName
                PSDrivePath           = $Node.PSDrivePath
                TempLocation          = $Node.TempLocation
                DependsOn             = "[cMDTDirectory]DeploymentFolder"
            }
        }

        ForEach ($Application in $Node.Applications)   
        {

            [string]$ApplicationSourcePath = $Application.ApplicationSourcePath
            If (-not(($ApplicationSourcePath -like "*:*") -or ($ApplicationSourcePath -like "*\\*")))
            {
                If ($weblink) { $ApplicationSourcePath = "$($Node.SourcePath)$($ApplicationSourcePath.Replace("\","/"))" }
                Else          { $ApplicationSourcePath = "$($Node.SourcePath)$($ApplicationSourcePath.Replace("/","\"))" }
            }

            cMDTApplication $Application.Name.Replace(' ','')
            {
                Ensure                = $Application.Ensure
                Name                  = $Application.Name
                Version               = $Application.Version
                Path                  = "$($Node.PSDriveName):$($Application.Path)"
                ShortName             = $Application.ShortName
                Publisher             = $Application.Publisher
                Language              = $Application.Language
                CommandLine           = $Application.CommandLine
                WorkingDirectory      = $Application.WorkingDirectory
                ApplicationSourcePath = $ApplicationSourcePath
                DestinationFolder     = $Application.DestinationFolder
                Enabled               = "True"
                PSDriveName           = $Node.PSDriveName
                PSDrivePath           = $Node.PSDrivePath
                TempLocation          = $Node.TempLocation
                DependsOn             = "[cMDTDirectory]DeploymentFolder"
            }
        }

        ForEach ($ApplicationBundle in $Node.ApplicationBundles)   
        {

            [string[]]$dependsOn = @()
            foreach ($application in $BundledApplications)
            {
                $dependsOn += "[cMDTApplication]$($application.Replace(' ',''))"
            }
            cMDTApplicationBundle $ApplicationBundle.BundleName.Replace(' ','')
            {
                Ensure              = $ApplicationBundle.Ensure
                BundleName          = $ApplicationBundle.BundleName
                BundledApplications = $ApplicationBundle.BundledApplications
                Version             = $ApplicationBundle.Version
                Publisher           = $ApplicationBundle.Publisher
                Language            = $ApplicationBundle.Language
                Hide                = $ApplicationBundle.Hide
                Enable              = $ApplicationBundle.Enable
                Folder              = $ApplicationBundle.Folder
                PSDriveName         = $Node.PSDriveName
                PSDrivePath         = $Node.PSDrivePath
                DependsOn           = $dependsOn
            }
        }

        ForEach ($CustomSetting in $Node.CustomSettings)   
        {

            If ($Node.SourcePath -like "*/*") { $weblink = $true }

            [string]$SourcePath = $CustomSetting.SourcePath
            If (-not(($SourcePath -like "*:*") -or ($SourcePath -like "*\\*")))
            {
                If ($weblink) { $SourcePath = "$($Node.SourcePath)$($SourcePath.Replace("\","/"))" }
                Else          { $SourcePath = "$($Node.SourcePath)$($SourcePath.Replace("/","\"))" }
            }

            cMDTCustomize $CustomSetting.Name.Replace(' ','')
            {
                Ensure               = $CustomSetting.Ensure
                Name                 = $CustomSetting.Name
                Version              = $CustomSetting.Version
                SourcePath           = $SourcePath
                Path                 = $Node.PSDrivePath
                TempLocation         = $Node.TempLocation
                #Protected = $Protected
                DependsOn            = "[cMDTDirectory]DeploymentFolder"
            }
        }

        ForEach ($IniFile in $Node.CustomizeIniFiles)   
        {

            If ($IniFile.Name -eq "CustomSettingsIni")
            {

                If ($IniFile.HomePage)             { $HomePage             = "Home_Page=$($IniFile.HomePage)" }                        Else { $HomePage             = ";Home_Page=" }
                If ($IniFile.SkipAdminPassword)    { $SkipAdminPassword    = "SkipAdminPassword=$($IniFile.SkipAdminPassword)" }       Else { $SkipAdminPassword    = ";SkipAdminPassword=" }
                If ($IniFile.SkipApplications)     { $SkipApplications     = "SkipApplications=$($IniFile.SkipApplications)" }         Else { $SkipApplications     = ";SkipApplications=" }
                If ($IniFile.SkipBitLocker)        { $SkipBitLocker        = "SkipBitLocker=$($IniFile.SkipBitLocker)" }               Else { $SkipBitLocker        = ";SkipBitLocker=" }
                If ($IniFile.SkipCapture)          { $SkipCapture          = "SkipCapture=$($IniFile.SkipCapture)" }                   Else { $SkipCapture          = ";SkipCapture=" }
                If ($IniFile.SkipComputerBackup)   { $SkipComputerBackup   = "SkipComputerBackup=$($IniFile.SkipComputerBackup)" }     Else { $SkipComputerBackup   = ";SkipComputerBackup=" }
                If ($IniFile.SkipComputerName)     { $SkipComputerName     = "SkipComputerName=$($IniFile.SkipComputerName)" }         Else { $SkipComputerName     = ";SkipComputerName=" }
                If ($IniFile.SkipDomainMembership) { $SkipDomainMembership = "SkipDomainMembership=$($IniFile.SkipDomainMembership)" } Else { $SkipDomainMembership = ";SkipDomainMembership=" }
                If ($IniFile.SkipFinalSummary)     { $SkipFinalSummary     = "SkipFinalSummary=$($IniFile.SkipFinalSummary)" }         Else { $SkipFinalSummary     = ";SkipFinalSummary=" }
                If ($IniFile.SkipLocaleSelection)  { $SkipLocaleSelection  = "SkipLocaleSelection=$($IniFile.SkipLocaleSelection)" }   Else { $SkipLocaleSelection  = ";SkipLocaleSelection=" }
                If ($IniFile.SkipPackageDisplay)   { $SkipPackageDisplay   = "SkipPackageDisplay=$($IniFile.SkipPackageDisplay)" }     Else { $SkipPackageDisplay   = ";SkipPackageDisplay=" }
                If ($IniFile.SkipProductKey)       { $SkipProductKey       = "SkipProductKey=$($IniFile.SkipProductKey)" }             Else { $SkipProductKey       = ";SkipProductKey=" }
                If ($IniFile.SkipRoles)            { $SkipRoles            = "SkipRoles=$($IniFile.SkipRoles)" }                       Else { $SkipRoles            = ";SkipRoles=" }
                If ($IniFile.SkipSummary)          { $SkipSummary          = "SkipSummary=$($IniFile.SkipSummary)" }                   Else { $SkipSummary          = ";SkipSummary=" }
                If ($IniFile.SkipTimeZone)         { $SkipTimeZone         = "SkipTimeZone=$($IniFile.SkipTimeZone)" }                 Else { $SkipTimeZone         = ";SkipTimeZone=" }
                If ($IniFile.SkipUserData)         { $SkipUserData         = "SkipUserData=$($IniFile.SkipUserData)" }                 Else { $SkipUserData         = ";SkipUserData=" }
                If ($IniFile.SkipTaskSequence)     { $SkipTaskSequence     = "SkipTaskSequence=$($IniFile.SkipTaskSequence)" }         Else { $SkipTaskSequence     = ";SkipTaskSequence=" }
                If ($IniFile.JoinDomain)           { $JoinDomain           = "JoinDomain=$($IniFile.JoinDomain)" }                     Else { $JoinDomain           = ";JoinDomain=" }
                If ($IniFile.DomainAdmin)          { $DomainAdmin          = "DomainAdmin=$($IniFile.DomainAdmin)" }                   Else { $DomainAdmin          = ";DomainAdmin=" }
                If ($IniFile.DomainAdminDomain)    { $DomainAdminDomain    = "DomainAdminDomain=$($IniFile.DomainAdminDomain)" }       Else { $DomainAdminDomain    = ";DomainAdminDomain=" }
                If ($IniFile.DomainAdminPassword)  { $DomainAdminPassword  = "DomainAdminPassword=$($IniFile.DomainAdminPassword)" }   Else { $DomainAdminPassword  = ";DomainAdminPassword=" }
                If ($IniFile.MachineObjectOU)      { $MachineObjectOU      = "MachineObjectOU=$($IniFile.MachineObjectOU)" }           Else { $MachineObjectOU      = ";MachineObjectOU=" }
                If ($IniFile.TimeZoneName)         { $TimeZoneName         = "TimeZoneName=$($IniFile.TimeZoneName)" }                 Else { $TimeZoneName         = ";TimeZoneName=" }
                If ($IniFile.WSUSServer)           { $WSUSServer           = "WSUSServer=$($IniFile.WSUSServer)" }                     Else { $WSUSServer           = ";WSUSServer=" }
                If ($IniFile.UserLocale)           { $UserLocale           = "UserLocale=$($IniFile.UserLocale)" }                     Else { $UserLocale           = ";UserLocale=" }
                If ($IniFile.KeyboardLocale)       { $KeyboardLocale       = "KeyboardLocale=$($IniFile.KeyboardLocale)" }             Else { $KeyboardLocale       = ";KeyboardLocale=" }
                If ($IniFile.UILanguage)           { $UILanguage           = "UILanguage=$($IniFile.UILanguage)" }                     Else { $UILanguage           = ";UILanguage=" }
                If ($IniFile.ProductKey)           { $ProductKey           = "ProductKey=$($IniFile.ProductKey)" }                     Else { $ProductKey           = ";ProductKey=" }
                If ($IniFile.EventService)         { $EventService         = "EventService=$($IniFile.EventService)" }                 Else { $EventService         = ";EventService=" }

                cMDTCustomSettingsIni ini {
                    Ensure    = $IniFile.Ensure
                    Path      = "$($Node.PSDrivePath)\$($IniFile.Path)"
                    DependsOn = "[cMDTDirectory]DeploymentFolder"
                    Content   = @"
[Settings]
Priority=SetModelAlias, Init, ModelAlias, Default
Properties=ModelAlias, ComputerSerialNumber
 
[SetModelAlias]
UserExit=ModelAliasExit.vbs
ModelAlias=#SetModelAlias()#
 
[Init]
ComputerSerialNumber=#Mid(Replace(Replace(oEnvironment.Item("SerialNumber")," ",""),"-",""),1,11)#
 
[Default]
OSInstall=Y
_SMSTSORGNAME=Company
HideShell=YES
DisableTaskMgr=YES
ApplyGPOPack=NO
UserDataLocation=NONE
DoCapture=NO
OSDComputerName=CLI%ComputerSerialNumber%
 
;Local admin password
AdminPassword=$($Node.LocalAdminPassword)
SLShare=%DeployRoot%\Logs
$($EventService)
 
OrgName=Company
$($HomePage)
 
;Enable or disable options:
$($SkipAdminPassword)
$($SkipApplications)
$($SkipBitLocker)
$($SkipCapture)
$($SkipComputerBackup)
$($SkipComputerName)
$($SkipDomainMembership)
$($SkipFinalSummary)
$($SkipLocaleSelection)
$($SkipPackageDisplay)
$($SkipProductKey)
$($SkipRoles)
$($SkipSummary)
$($SkipTimeZone)
$($SkipUserData)
$($SkipTaskSequence)
$($ProductKey)
 
;DomainJoin
$($JoinDomain)
$($DomainAdmin)
$($DomainAdminDomain)
$($DomainAdminPassword)
$($MachineObjectOU)
 
;TimeZone settings
$($TimeZoneName)
 
$($WSUSServer)
 
;Example keyboard layout.
$($UserLocale)
$($KeyboardLocale)
$($UILanguage)
 
;Drivers
DriverSelectionProfile=Nothing
 
;DriverInjectionMode=ALL
 
FinishAction=RESTART
"@

                }

            }

            If ($IniFile.Name -eq "BootstrapIni")
            {

                If ($IniFile.DeployRoot)       { $DeployRoot       = "DeployRoot=\\$($env:COMPUTERNAME)$($IniFile.DeployRoot)" } Else { $DeployRoot       = ";DeployRoot=" }
                If ($IniFile.KeyboardLocalePE) { $KeyboardLocalePE = "KeyboardLocalePE=$($IniFile.KeyboardLocalePE)" }         Else { $KeyboardLocalePE = ";KeyboardLocalePE=" }

                cMDTBootstrapIni ini {
                    Ensure    = $IniFile.Ensure
                    Path      = "$($Node.PSDrivePath)\$($IniFile.Path)"
                    DependsOn = "[cMDTDirectory]DeploymentFolder"
                    Content   = @"
[Settings]
Priority=Default
 
[Default]
$($DeployRoot)
SkipBDDWelcome=YES
 
;MDT Connect Account
UserID=$($Node.MDTLocalAccount)
UserPassword=$($Node.MDTLocalPassword)
UserDomain=$($env:COMPUTERNAME)
 
;Keyboard Layout
$($KeyboardLocalePE)
"@

                }
            }

        }

        ForEach ($Image in $Node.BootImage)   
        {

            cMDTUpdateBootImage updateBootImage
            {
                Version                 = $Image.Version
                PSDeploymentShare       = $Node.PSDriveName
                Force                   = $true
                Compress                = $true
                DeploymentSharePath     = $Node.PSDrivePath
                ExtraDirectory          = $Image.ExtraDirectory
                BackgroundFile          = $Image.BackgroundFile
                LiteTouchWIMDescription = $Image.LiteTouchWIMDescription
                FeaturePacks            = $Image.FeaturePacks
                DependsOn               = "[cMDTDirectory]DeploymentFolder"
            }
        
            cWDSBootImage wdsBootImage
            {
                Ensure    = $Image.Ensure
                Version   = $Image.Version
                Path      = "$($Node.PSDrivePath)$($Image.Path)"
                ImageName = $Image.ImageName
                DependsOn = "[cMDTDirectory]DeploymentFolder"
            }

        }

        <#
        cMDTMonitorService enableMDTMonitorService
        {
            Ensure = $Image.Ensure
            IsSingleInstance = "Yes"
            PSDriveName = $Node.PSDriveName
            PSDrivePath = $Node.PSDrivePath
            MonitorHost = $env:COMPUTERNAME
            DependsOn = "[Package]MDT"
        }
        #>


    }
}


#Get configuration data
[hashtable]$ConfigurationData = Get-ConfigurationDataAsObject -ConfigurationData "$PSScriptRoot\Deploy_MDT_Server_ConfigurationData.psd1"

#Create DSC MOF job
DeployMDTServerContract -OutputPath "$PSScriptRoot\MDT-Deploy_MDT_Server" -ConfigurationData $ConfigurationData

#Set DSC LocalConfigurationManager
Set-DscLocalConfigurationManager -Path "$PSScriptRoot\MDT-Deploy_MDT_Server" -Verbose

#Start DSC MOF job
Start-DscConfiguration -Wait -Force -Verbose -ComputerName "$env:computername" -Path "$PSScriptRoot\MDT-Deploy_MDT_Server"

Write-Output ""
Write-Output "AddLevel Deploy MDT Server Builder completed!"