-
-
Notifications
You must be signed in to change notification settings - Fork 358
/
AutomatedLabDefinition.psm1
3164 lines (2697 loc) · 136 KB
/
AutomatedLabDefinition.psm1
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region Internals
$unattendedXmlDefaultContent2012 = @'
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="generalize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DoNotCleanTaskBar>true</DoNotCleanTaskBar>
</component>
<component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SkipRearm>1</SkipRearm>
</component>
</settings>
<settings pass="specialize">
<component name="Security-Malware-Windows-Defender" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DisableAntiSpyware>true</DisableAntiSpyware>
</component>
<component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<Identification>
<JoinWorkgroup xmlns="">NET</JoinWorkgroup>
</Identification>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<ComputerName>SERVER</ComputerName>
<RegisteredOrganization>vm.net</RegisteredOrganization>
<RegisteredOwner>NA</RegisteredOwner>
<DoNotCleanTaskBar>true</DoNotCleanTaskBar>
<TimeZone>UTC</TimeZone>
</component>
<component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Home_Page>about:blank</Home_Page>
<DisableFirstRunWizard>true</DisableFirstRunWizard>
<DisableOOBAccelerators>true</DisableOOBAccelerators>
<DisableDevTools>true</DisableDevTools>
<LocalIntranetSites></LocalIntranetSites>
<TrustedSites></TrustedSites>
</component>
<component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAuthentication>0</UserAuthentication>
</component>
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunSynchronous>
<RunSynchronousCommand wcm:action="add">
<Description>EnableAdmin</Description>
<Order>1</Order>
<Path>cmd /c net user Administrator /active:yes</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>UnfilterAdministratorToken</Description>
<Order>2</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v FilterAdministratorToken /t REG_DWORD /d 0 /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Remove First Logon Animation</Description>
<Order>3</Order>
<Path>cmd /c reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v EnableFirstLogonAnimation /d 0 /t REG_DWORD /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Do Not Open Server Manager At Logon</Description>
<Order>4</Order>
<Path>cmd /c reg add "HKLM\SOFTWARE\Microsoft\ServerManager" /v "DoNotOpenServerManagerAtLogon" /d 1 /t REG_DWORD /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Do not Open Initial Configuration Tasks At Logon</Description>
<Order>5</Order>
<Path>cmd /c reg add "HKLM\SOFTWARE\Microsoft\ServerManager\oobe" /v "DoNotOpenInitialConfigurationTasksAtLogon" /d 1 /t REG_DWORD /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Set Power Scheme to High Performance</Description>
<Order>6</Order>
<Path>cmd /c powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Don't require password when console wakes up</Description>
<Order>7</Order>
<Path>cmd /c powercfg -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c fea3413e-7e05-4911-9a71-700331f1c294 0e796bdb-100d-47d6-a2d5-f7d2daa51f51 0</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Sleep timeout</Description>
<Order>8</Order>
<Path>cmd /c powercfg -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 238c9fa8-0aad-41ed-83f4-97be242c8f20 29f6c1db-86da-48c5-9fdb-f2b67b1f44da 0</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>monitor timeout</Description>
<Order>9</Order>
<Path>cmd /c powercfg -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 7516b95f-f776-4464-8c53-06167f40cc99 3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e 0</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable PowerShell Remoting 1</Description>
<Order>10</Order>
<Path>cmd /c winrm quickconfig -quiet</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable PowerShell Remoting 2</Description>
<Order>11</Order>
<Path>cmd /c winrm quickconfig -quiet -force</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable PowerShell Remoting 3</Description>
<Order>12</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell /v ExecutionPolicy /t REG_SZ /d Unrestricted /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Disable UAC</Description>
<Order>13</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system /v EnableLUA /t REG_DWORD /d 0 /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Configure BgInfo to start automatically</Description>
<Order>14</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v BgInfo /t REG_SZ /d "C:\Windows\BgInfo.exe C:\Windows\BgInfo.bgi /Timer:0 /nolicprompt" /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable Remote Desktop firewall rules</Description>
<Order>15</Order>
<Path>cmd /c netsh advfirewall Firewall set rule group="Remote Desktop" new enable=yes</Path>
</RunSynchronousCommand>
</RunSynchronous>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>EN-US</SystemLocale>
<UILanguage>EN-US</UILanguage>
<UserLocale>EN-US</UserLocale>
</component>
<component name="Microsoft-Windows-TapiSetup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<TapiConfigured>0</TapiConfigured>
<TapiUnattendLocation>
<AreaCode>""</AreaCode>
<CountryOrRegion>1</CountryOrRegion>
<LongDistanceAccess>9</LongDistanceAccess>
<OutsideAccess>9</OutsideAccess>
<PulseOrToneDialing>1</PulseOrToneDialing>
<DisableCallWaiting>""</DisableCallWaiting>
<InternationalCarrierCode>""</InternationalCarrierCode>
<LongDistanceCarrierCode>""</LongDistanceCarrierCode>
<Name>Default</Name>
</TapiUnattendLocation>
</component>
<component name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<IEHardenAdmin>false</IEHardenAdmin>
<IEHardenUser>false</IEHardenUser>
</component>
<component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fDenyTSConnections>false</fDenyTSConnections>
</component>
<component name="Networking-MPSSVC-Svc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<component name="Microsoft-Windows-TCPIP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<component name="Microsoft-Windows-DNS-Client" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<component name="Microsoft-Windows-NetBT" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>winrm quickconfig -quiet</CommandLine>
<Description>Enable Windows Remoting</Description>
<Order>1</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>winrm quickconfig -quiet -force</CommandLine>
<Description>Enable Windows Remoting</Description>
<Order>2</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>winrm set winrm/config/service/auth @{CredSSP="true"}</CommandLine>
<Description>Enable Windows Remoting CredSSP</Description>
<Order>3</Order>
</SynchronousCommand>
</FirstLogonCommands>
<UserAccounts>
<AdministratorPassword>
<Value>Password1</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>Password1</Value>
<PlainText>true</PlainText>
</Password>
<Group>Administrators</Group>
<DisplayName>AL</DisplayName>
<Name>AL</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<NetworkLocation>Work</NetworkLocation>
<ProtectYourPC>3</ProtectYourPC>
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideLocalAccountScreen>true</HideLocalAccountScreen>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
</OOBE>
<RegisteredOrganization>vm.net</RegisteredOrganization>
<RegisteredOwner>NA</RegisteredOwner>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>En-US</SystemLocale>
<UILanguage>EN-US</UILanguage>
<UserLocale>EN-Us</UserLocale>
</component>
</settings>
</unattend>
'@
$unattendedXmlDefaultContent2008 = @'
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="generalize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DoNotCleanTaskBar>true</DoNotCleanTaskBar>
</component>
<component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SkipRearm>1</SkipRearm>
</component>
</settings>
<settings pass="specialize">
<component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<Identification>
<JoinWorkgroup xmlns="">NET</JoinWorkgroup>
</Identification>
</component>
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<ComputerName>SERVER</ComputerName>
<RegisteredOrganization>vm.net</RegisteredOrganization>
<RegisteredOwner>NA</RegisteredOwner>
<DoNotCleanTaskBar>true</DoNotCleanTaskBar>
<TimeZone>UTC</TimeZone>
</component>
<component name="Microsoft-Windows-IE-InternetExplorer" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Home_Page>about:blank</Home_Page>
<DisableFirstRunWizard>true</DisableFirstRunWizard>
<DisableOOBAccelerators>true</DisableOOBAccelerators>
<DisableDevTools>true</DisableDevTools>
<LocalIntranetSites>http://*.vm.net;https://*.vm.net</LocalIntranetSites>
<TrustedSites>https://*.vm.net</TrustedSites>
</component>
<component name="Microsoft-Windows-TerminalServices-RDP-WinStationExtensions" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAuthentication>0</UserAuthentication>
</component>
<component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RunSynchronous>
<RunSynchronousCommand wcm:action="add">
<Description>Disable and stop Windows Firewall 1</Description>
<Order>1</Order>
<Path>cmd /c sc config MpsSvc start=disabled</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Disable and stop Windows Firewall 2</Description>
<Order>2</Order>
<Path>cmd /c sc stop MpsSvc</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>EnableAdmin</Description>
<Order>3</Order>
<Path>cmd /c net user Administrator /active:yes</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>UnfilterAdministratorToken</Description>
<Order>4</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v FilterAdministratorToken /t REG_DWORD /d 0 /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Remove First Logon Animation</Description>
<Order>5</Order>
<Path>cmd /c reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v EnableFirstLogonAnimation /d 0 /t REG_DWORD /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Do Not Open Server Manager At Logon</Description>
<Order>6</Order>
<Path>cmd /c reg add "HKLM\SOFTWARE\Microsoft\ServerManager" /v "DoNotOpenServerManagerAtLogon" /d 1 /t REG_DWORD /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Do not Open Initial Configuration Tasks At Logon</Description>
<Order>7</Order>
<Path>cmd /c reg add "HKLM\SOFTWARE\Microsoft\ServerManager\oobe" /v "DoNotOpenInitialConfigurationTasksAtLogon" /d 1 /t REG_DWORD /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Set Power Scheme to High Performance</Description>
<Order>8</Order>
<Path>cmd /c powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Don't require password when console wakes up</Description>
<Order>9</Order>
<Path>cmd /c powercfg -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c fea3413e-7e05-4911-9a71-700331f1c294 0e796bdb-100d-47d6-a2d5-f7d2daa51f51 0</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Sleep timeout</Description>
<Order>10</Order>
<Path>cmd /c powercfg -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 238c9fa8-0aad-41ed-83f4-97be242c8f20 29f6c1db-86da-48c5-9fdb-f2b67b1f44da 0</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>monitor timeout</Description>
<Order>11</Order>
<Path>cmd /c powercfg -setacvalueindex 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 7516b95f-f776-4464-8c53-06167f40cc99 3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e 0</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable PowerShell Remoting 1</Description>
<Order>12</Order>
<Path>cmd /c winrm quickconfig -quiet</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable PowerShell Remoting 2</Description>
<Order>13</Order>
<Path>cmd /c winrm quickconfig -quiet -force</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable PowerShell Remoting 2</Description>
<Order>14</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell /v ExecutionPolicy /t REG_SZ /d Unrestricted /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Disable UAC</Description>
<Order>15</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system /v EnableLUA /t REG_DWORD /d 0 /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Configure BgInfo to start automatically</Description>
<Order>16</Order>
<Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v BgInfo /t REG_SZ /d "C:\Windows\BgInfo.exe C:\Windows\BgInfo.bgi /Timer:0 /nolicprompt" /f</Path>
</RunSynchronousCommand>
<RunSynchronousCommand wcm:action="add">
<Description>Enable Remote Desktop firewall rules</Description>
<Order>17</Order>
<Path>cmd /c netsh advfirewall Firewall set rule group="Remote Desktop" new enable=yes</Path>
</RunSynchronousCommand>
</RunSynchronous>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>EN-US</SystemLocale>
<UILanguage>EN-US</UILanguage>
<UserLocale>EN-US</UserLocale>
</component>
<component name="Microsoft-Windows-TapiSetup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<TapiConfigured>0</TapiConfigured>
<TapiUnattendLocation>
<AreaCode>""</AreaCode>
<CountryOrRegion>1</CountryOrRegion>
<LongDistanceAccess>9</LongDistanceAccess>
<OutsideAccess>9</OutsideAccess>
<PulseOrToneDialing>1</PulseOrToneDialing>
<DisableCallWaiting>""</DisableCallWaiting>
<InternationalCarrierCode>""</InternationalCarrierCode>
<LongDistanceCarrierCode>""</LongDistanceCarrierCode>
<Name>Default</Name>
</TapiUnattendLocation>
</component>
<component name="Microsoft-Windows-IE-ESC" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<IEHardenAdmin>false</IEHardenAdmin>
<IEHardenUser>false</IEHardenUser>
</component>
<component name="Microsoft-Windows-TerminalServices-LocalSessionManager" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fDenyTSConnections>false</fDenyTSConnections>
</component>
<component name="Networking-MPSSVC-Svc" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<component name="Microsoft-Windows-TCPIP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<component name="Microsoft-Windows-DNS-Client" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<component name="Microsoft-Windows-NetBT" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd /c sc config MpsSvc start=disabled</CommandLine>
<Description>1</Description>
<Order>1</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd /c sc stop MpsSvc</CommandLine>
<Description>2</Description>
<Order>2</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>winrm quickconfig -quiet</CommandLine>
<Description>Enable Windows Remoting</Description>
<Order>3</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>winrm quickconfig -quiet -force</CommandLine>
<Description>Enable Windows Remoting</Description>
<Order>4</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>winrm set winrm/config/service/auth @{CredSSP="true"}</CommandLine>
<Description>Enable Windows Remoting CredSSP</Description>
<Order>5</Order>
</SynchronousCommand>
</FirstLogonCommands>
<UserAccounts>
<AdministratorPassword>
<Value>Password1</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>Password1</Value>
<PlainText>true</PlainText>
</Password>
<Group>Administrators</Group>
<DisplayName>AL</DisplayName>
<Name>AL</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<NetworkLocation>Work</NetworkLocation>
<ProtectYourPC>3</ProtectYourPC>
</OOBE>
<RegisteredOrganization>vm.net</RegisteredOrganization>
<RegisteredOwner>NA</RegisteredOwner>
</component>
<component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>En-US</SystemLocale>
<UILanguage>EN-US</UILanguage>
<UserLocale>EN-Us</UserLocale>
</component>
</settings>
</unattend>
'@
#region Get-LabVolumesOnPhysicalDisks
function Get-LabVolumesOnPhysicalDisks
{
# .ExternalHelp AutomatedLabDefinition.Help.xml
$physicalDisks = Get-PhysicalDisk
$disks = Get-CimInstance -Class Win32_DiskDrive
$labVolumes = foreach ($disk in $disks)
{
$query = 'ASSOCIATORS OF {{Win32_DiskDrive.DeviceID="{0}"}} WHERE AssocClass=Win32_DiskDriveToDiskPartition' -f $disk.DeviceID.Replace('\', '\\')
$partitions = Get-CimInstance -Query $query
foreach ($partition in $partitions)
{
$query = 'ASSOCIATORS OF {{Win32_DiskPartition.DeviceID="{0}"}} WHERE AssocClass=Win32_LogicalDiskToPartition' -f $partition.DeviceID
$volumes = Get-CimInstance -Query $query
foreach ($volume in $volumes)
{
Get-Volume -DriveLetter $volume.DeviceId[0] |
Add-Member -Name Serial -MemberType NoteProperty -Value $disk.SerialNumber -PassThru |
Add-Member -Name Signature -MemberType NoteProperty -Value $disk.Signature -PassThru
}
}
}
$labVolumes |
Select-Object -ExpandProperty DriveLetter |
Sort-Object |
ForEach-Object {
$localDisk = New-Object AutomatedLab.LocalDisk($_)
$localDisk.Serial = $_.Serial
$localDisk.Signature = $_.Signature
$localDisk
}
}
#endregion Get-LabVolumesOnPhysicalDisks
#endregion Internals
#region Lab Definition Functions
#region New-LabDefinition
function New-LabDefinition
{
# .ExternalHelp AutomatedLabDefinition.Help.xml
[CmdletBinding()]
param (
[string]$Name,
[string]$Path,
[string]$VmPath,
[int]$ReferenceDiskSizeInGB = 50,
[int]$MaxMemory = 0,
[hashtable]$Notes,
[switch]$UseAllMemory = $false,
[switch]$UseStaticMemory = $false,
[ValidateSet('Azure', 'HyperV', 'VMWare')]
[string]$DefaultVirtualizationEngine,
[switch]$NoAzurePublishSettingsFile,
[string]$AzureSubscriptionName
)
Write-LogFunctionEntry
$hostOSVersion = [System.Version](Get-CimInstance -ClassName Win32_OperatingSystem).Version
if (($hostOSVersion -lt [System.Version]'6.2') -or (($hostOSVersion -ge [System.Version]'6.4') -and ($hostOSVersion -lt [System.Version]'10.0.10122')))
{
$osName = $((Get-CimInstance -ClassName Win32_OperatingSystem).Caption.PadRight(10))
$osBuild = $((Get-CimInstance -ClassName Win32_OperatingSystem).Version.PadRight(11))
'***************************************************************************'
' THIS HOST MACHINE IS NOT RUNNING AN OS SUPPORTED BY AUTOMATEDLAB!'
''
' Operating System detected as:'
" Name: $osName"
" Build: $osBuild"
''
' AutomatedLab is supported on the following virtualization platforms'
''
' - Microsoft Azure'
' - Windows 10 build 10.0.10122 or newer'
' - Windows 8.0 Professional'
' - Windows 8.0 Enterprise'
' - Windows 8.1 Professional'
' - Windows 8.1 Enterprise'
' - Windows 2012 Server Standard'
' - Windows 2012 Server DataCenter'
' - Windows 2012 R2 Server Standard'
' - Windows 2012 R2 Server DataCenter'
'***************************************************************************'
}
#settings for a new log
#reset the log and its format
$Global:AL_DeploymentStart = $null
$Global:taskStart = @()
$Global:indent = 0
$Global:labDeploymentNoNewLine = $false
$Script:reservedAddressSpaces = $null
Write-ScreenInfo -Message 'Initialization' -TimeDelta ([timespan]0) -TimeDelta2 ([timespan]0) -TaskStart
Write-ScreenInfo -Message "Host operating system version: '$($hostOSVersion.ToString())'"
if (-not $Name)
{
$reservedMacAddresses = @()
#Microsoft
$reservedMacAddresses += '00:03:FF'
$reservedMacAddresses += '00:0D:3A'
$reservedMacAddresses += '00:12:5A'
$reservedMacAddresses += '00:15:5D'
$reservedMacAddresses += '00:17:FA'
$reservedMacAddresses += '00:50:F2'
$reservedMacAddresses += '00:1D:D8'
#VMware
$reservedMacAddresses += '00:05:69'
$reservedMacAddresses += '00:0C:29'
$reservedMacAddresses += '00:1C:14'
$reservedMacAddresses += '00:50:56'
#Citrix
$reservedMacAddresses += '00:16:3E'
$macAddress = Get-WmiObject Win32_NetworkAdapter |
Where-Object { $_.NetEnabled -and $_.NetConnectionID } |
Where-Object { $_.MACaddress.ToString().SubString(0, 8) -notin $reservedMacAddresses } |
Select-Object -ExpandProperty MACAddress -Unique
$Name = "$($env:COMPUTERNAME)$($macAddress.SubString(12,2))$($macAddress.SubString(15,2))"
Write-ScreenInfo -Message "Lab name and network name has automatically been generated as '$Name' (if not overridden)"
}
Write-ScreenInfo -Message "Creating new lab definition with name '$Name'"
#remove the current lab from memory
if (Get-Lab -ErrorAction SilentlyContinue)
{
Clear-Lab
}
$global:labExported = $false
$global:firstAzureVMCreated = $false
$global:existingAzureNetworks = @()
$global:cacheVMs = $null
$script:existingHyperVVirtualSwitches = $null
#cleanup $PSDefaultParameterValues for entries for AL functions
$automatedLabPSDefaultParameterValues = $global:PSDefaultParameterValues.GetEnumerator() | Where-Object {(Get-Command ($_.Name).Split(':')[0]).Module -like 'Automated*'}
if ($automatedLabPSDefaultParameterValues)
{
foreach ($entry in $automatedLabPSDefaultParameterValues)
{
$global:PSDefaultParameterValues.Remove($entry.Name)
Write-ScreenInfo -Message "Entry '$($entry.Name)' with value '$($entry.Value)' was removed from `$PSDefaultParameterValues. If needed, modify `$PSDefaultParameterValues after calling New-LabDefinition'" -Type Warning
}
}
if (Get-Variable -Name 'autoIPAddress' -Scope Script -ErrorAction SilentlyContinue)
{
Remove-Variable -Name 'AutoIPAddress' -Scope Script
}
if ($global:labNamePrefix) { $Name = "$global:labNamePrefix$Name" }
if ($PSBoundParameters.ContainsKey('Path'))
{
$script:labPath = $Path
}
else
{
$script:labpath = "$([System.Environment]::GetFolderPath('MyDocuments'))\AutomatedLab-Labs\$Name"
}
Write-ScreenInfo -Message "Location of lab definition files will be '$($script:labpath)'"
$script:defaults = $MyInvocation.MyCommand.Module.PrivateData
$script:lab = New-Object AutomatedLab.Lab
$script:lab.Name = $Name
#Update SysInternals suite if needed
$type = Get-Type -GenericType AutomatedLab.DictionaryXmlStore -T String, DateTime
try
{
Write-Verbose -Message 'Get last check time of SysInternals suite'
$timestamps = $type::ImportFromRegistry('Cache', 'Timestamps')
$lastChecked = $timestamps.SysInternalsUpdateLastChecked
Write-Verbose -Message "Last check was '$lastChecked'."
}
catch
{
Write-Verbose -Message 'Last check time could not be retrieved. SysInternals suite never updated'
$lastChecked = Get-Date -Year 1601
$timestamps = New-Object $type
}
if ($lastChecked)
{
$lastChecked = $lastChecked.AddDays(7)
}
if ((Get-Date) -gt $lastChecked)
{
Write-Verbose -Message 'Last check time is more then a week ago. Check web site for update.'
$sysInternalsUrl = (Get-Module -Name AutomatedLab)[0].PrivateData.SysInternalsUrl
$sysInternalsDownloadUrl = (Get-Module -Name AutomatedLab)[0].PrivateData.SysInternalsDownloadUrl
try
{
Write-Verbose -Message 'Web page downloaded'
$webRequest = Invoke-WebRequest -Uri $sysInternalsURL -UseBasicParsing
$pageDownloaded = $true
}
catch
{
Write-Verbose -Message 'Web page could not be downloaded'
Write-ScreenInfo -Message "No connection to '$sysInternalsURL'. Skipping." -Type Error
$pageDownloaded = $false
}
if ($pageDownloaded)
{
$updateStart = $webRequest.Content.IndexOf('Updated') + 'Updated:'.Length
$updateFinish = $webRequest.Content.IndexOf('</p>', $updateStart)
$updateStringFromWebPage = $webRequest.Content.Substring($updateStart, $updateFinish - $updateStart).Trim()
Write-Verbose -Message "Update string from web page: '$updateStringFromWebPage'"
$type = Get-Type -GenericType AutomatedLab.DictionaryXmlStore -T String, String
try
{
$versions = $type::ImportFromRegistry('Cache', 'Versions')
}
catch
{
$versions = New-Object $type
}
Write-Verbose -Message "Update string from registry: '$currentVersion'"
if ($versions['SysInternals'] -ne $updateStringFromWebPage)
{
Write-ScreenInfo -Message 'Performing update of SysInternals suite now' -Type Warning -TaskStart
Start-Sleep -Seconds 1
#Download SysInternals suite
$tempFilePath = [System.IO.Path]::GetTempFileName()
$tempFilePath = Rename-Item -Path $tempFilePath -NewName ([System.IO.Path]::ChangeExtension($tempFilePath, '.zip')) -PassThru
Write-Verbose -Message "Temp file: '$tempFilePath'"
try
{
Invoke-WebRequest -Uri $sysInternalsDownloadURL -UseBasicParsing -OutFile $tempFilePath
$fileDownloaded = $true
Write-Verbose -Message "File '$sysInternalsDownloadURL' downloaded"
}
catch
{
Write-ScreenInfo -Message "File '$sysInternalsDownloadURL' could not be downloaded. Skipping." -Type Error -TaskEnd
$fileDownloaded = $false
}
if ($fileDownloaded)
{
Unblock-File -Path $tempFilePath
#Extract files to Tools folder
if (-not (Test-Path -Path "$labSources\Tools"))
{
Write-Verbose -Message "Folder '$labSources\Tools' does not exist. Creating now."
New-Item -ItemType Directory -Path "$labSources\Tools" | Out-Null
}
if (-not (Test-Path -Path "$labSources\Tools\SysInternals"))
{
Write-Verbose -Message "Folder '$labSources\Tools\SysInternals' does not exist. Creating now."
New-Item -ItemType Directory -Path "$labSources\Tools\SysInternals" | Out-Null
}
else
{
Write-Verbose -Message "Folder '$labSources\Tools\SysInternals' exist. Removing it now and recreating it."
Remove-Item -Path "$labSources\Tools\SysInternals" -Recurse | Out-Null
New-Item -ItemType Directory -Path "$labSources\Tools\SysInternals" | Out-Null
}
Write-Verbose -Message 'Extracting files'
Expand-Archive -Path $tempFilePath -DestinationPath "$labSources\Tools\SysInternals"
Remove-Item -Path $tempFilePath
#Update registry
$versions['SysInternals'] = $updateStringFromWebPage
$versions.ExportToRegistry('Cache', 'Versions')
$timestamps['SysInternalsUpdateLastChecked'] = Get-Date
$timestamps.ExportToRegistry('Cache', 'Timestamps')
Write-ScreenInfo -Message "SysInternals Suite has been updated and placed in '$labSources\Tools\SysInternals'" -Type Warning -TaskEnd
}
}
}
}
while (Get-LabVirtualNetworkDefinition)
{
Remove-LabVirtualNetworkDefinition -Name (Get-LabVirtualNetworkDefinition)[0].Name
}
$machineDefinitionFilePath = Join-Path -Path $script:labPath -ChildPath $defaults.MachineFileName
$machineDefinitionFile = New-Object AutomatedLab.MachineDefinitionFile
$machineDefinitionFile.Path = $machineDefinitionFilePath
$script:lab.MachineDefinitionFiles.Add($machineDefinitionFile)
$diskDefinitionFilePath = Join-Path -Path $script:labPath -ChildPath $defaults.DiskFileName
$diskDefinitionFile = New-Object AutomatedLab.DiskDefinitionFile
$diskDefinitionFile.Path = $diskDefinitionFilePath
$script:lab.DiskDefinitionFiles.Add($diskDefinitionFile)
$sourcesPath = $labSources
if (-not $sourcesPath)
{
$sourcesPath = New-LabSourcesFolder
}
Write-ScreenInfo -Message "Location of LabSources folder is '$sourcesPath'"
if (-not (Get-LabIsoImageDefinition) -and $DefaultVirtualizationEngine -ne 'Azure')
{
if (Get-ChildItem -Path "$(Get-LabSourcesLocation)\ISOs" -Filter *.iso -Recurse)
{
Write-ScreenInfo -Message 'Auto-adding ISO files' -TaskStart
Add-LabIsoImageDefinition -Path "$(Get-LabSourcesLocation)\ISOs"
Write-ScreenInfo -Message 'Done' -TaskEnd
}
else
{
Write-ScreenInfo -Message "No ISO files found in $(Get-LabSourcesLocation)\ISOs folder. If using Hyper-V for lab machines, please add ISO files manually using 'Add-LabIsoImageDefinition'" -Type Warning
}
}
if ($DefaultVirtualizationEngine)
{
$script:lab.DefaultVirtualizationEngine = $DefaultVirtualizationEngine
}
if ($MaxMemory -ne 0)
{
$script:lab.MaxMemory = $MaxMemory
}
if ($UseAllMemory)
{
$script:lab.MaxMemory = 4TB
}
$script:lab.UseStaticMemory = $UseStaticMemory
$script:lab.Sources.UnattendedXml = $script:labPath
if ($VmPath)
{
$Script:lab.target.Path = $vmPath
Write-ScreenInfo -Message "Path for VMs specified as '$($script:lab.Target.Path)'" -Type Info
}
$script:lab.Target.ReferenceDiskSizeInGB = $ReferenceDiskSizeInGB
$type = Get-Type -GenericType AutomatedLab.ListXmlStore -T AutomatedLab.Machine
$script:machines = New-Object $type
$type = Get-Type -GenericType AutomatedLab.ListXmlStore -T AutomatedLab.Disk
$script:disks = New-Object $type
$script:lab.Notes = $Notes
Write-LogFunctionExit
}
#endregion New-LabDefinition
#region Get-LabDefinition
function Get-LabDefinition
{
# .ExternalHelp AutomatedLabDefinition.Help.xml
[CmdletBinding()]
[OutputType([AutomatedLab.Lab])]
param ()
Write-LogFunctionEntry
return $script:lab
Write-LogFunctionExit
}
#endregion Get-LabDefinition
#region Set-LabDefinition
function Set-LabDefinition
{
param
(
[AutomatedLab.Lab]
$Lab,
[AutomatedLab.Machine[]]
$Machines,
[AutomatedLab.Disk[]]
$Disks
)
if ($Lab)
{
$script:lab = $Lab
}
if ($Machines)
{
$script:Machines.Clear()
$Machines | Foreach-Object { $script:Machines.Add($_)}
}
if ($Disks)
{
$script:Disks.Clear()
$Disks | ForEach-Object { $script:Disks.Add($_) }
}
}
#endregion
#region Export-LabDefinition
function Export-LabDefinition
{
# .ExternalHelp AutomatedLabDefinition.Help.xml
[CmdletBinding()]
param (
[switch]
$Force,
[switch]
$ExportDefaultUnattendedXml = $true,
[switch]
$Silent
)
Write-LogFunctionEntry
if (Get-LabMachineDefinition | Where-Object HostType -eq 'HyperV')
{
$osesCount = (Get-LabAvailableOperatingSystem).Count
}
#Automatic DNS configuration in Azure if no DNS server is specified and an AD is being deployed
foreach ($network in (Get-LabVirtualNetworkDefinition))
{
if ($network.HostType -eq 'Azure' -and (Get-LabMachineDefinition -Role RootDC))
{
$rootDCs = Get-LabMachineDefinition -Role RootDC
$dnsServerIP = ''
if ($rootDCs | Where-Object Network -eq $network)
{
$dnsServerIP = ($rootDCs)[0].IpV4Address
}
elseif ($rootDCs | Where-Object Network -eq $network)
{
$dnsServerIP = ($rootDCs | Where-Object Network -eq $network)[0].IpV4Address
}
if (-not ((Get-LabVirtualNetworkDefinition)[0].DnsServers) -and $dnsServerIP)
{
(Get-LabVirtualNetworkDefinition)[0].DnsServers = $dnsServerIP
$dnsServerName = (Get-LabMachineDefinition | Where-Object {$_.IpV4Address -eq $dnsServerIP}).Name
if (-not $Silent)
{
Write-ScreenInfo -Message "No DNS server was defined for Azure virtual network while AD is being deployed. Setting DNS server to IP address of '$dnsServerName'" -Type Warning
}
}
}
}
#Automatic DNS (client) configuration of machines
$firstRootDc = Get-LabMachineDefinition -Role RootDC | Select-Object -First 1
$firstRouter = Get-LabMachineDefinition -Role Routing | Select-Object -First 1
$firstRouterExternalSwitch = $firstRouter.NetworkAdapters | Where-Object { $_.VirtualSwitch.SwitchType -eq 'External' }
if ($firstRootDc -or $firstRouter)
{
foreach ($machine in (Get-LabMachineDefinition))
{
if ($firstRouter)
{
$mappingNetworks = Compare-Object -ReferenceObject $firstRouter.NetworkAdapters.VirtualSwitch.Name `
-DifferenceObject $machine.NetworkAdapters.VirtualSwitch.Name -ExcludeDifferent -IncludeEqual
}
foreach ($networkAdapter in $machine.NetworkAdapters)
{
if ($networkAdapter.IPv4DnsServers -contains '0.0.0.0')
{
if (-not $machine.IsDomainJoined) #machine is not domain joined, the 1st network adapter's IP of the 1st root DC is used as DNS server
{
if ($firstRootDc)
{
$networkAdapter.IPv4DnsServers = $firstRootDc.NetworkAdapters[0].Ipv4Address[0].IpAddress
}
elseif ($firstRouter)
{
if ($networkAdapter.VirtualSwitch.Name -in $mappingNetworks.InputObject)
{
$networkAdapter.IPv4DnsServers = ($firstRouter.NetworkAdapters | Where-Object { $_.VirtualSwitch.Name -eq $networkAdapter.VirtualSwitch.Name }).Ipv4Address.IpAddress
}
}
}
elseif ($machine.Roles.Name -contains 'RootDC') #if the machine is RootDC, its 1st network adapter's IP is used for DNS
{
$networkAdapter.IPv4DnsServers = $machine.NetworkAdapters[0].Ipv4Address[0].IpAddress
}
elseif ($machine.Roles.Name -contains 'FirstChildDC') #if it is a FirstChildDc, the 1st network adapter's IP of the corresponsing RootDC is used
{
$firstChildDcRole = $machine.Roles | Where-Object Name -eq 'FirstChildDC'
$roleParentDomain = $firstChildDcRole.Properties.ParentDomain
$rootDc = Get-LabMachineDefinition -Role RootDC | Where-Object DomainName -eq $roleParentDomain
$networkAdapter.IPv4DnsServers = $rootDc.NetworkAdapters[0].Ipv4Address[0].IpAddress
}
else #machine is domain joined and not a RootDC or FirstChildDC
{
Write-Verbose "Looking for a root DC in the machine's domain '$($machine.DomainName)'"
$rootDc = Get-LabMachineDefinition -Role RootDC | Where-Object DomainName -eq $machine.DomainName
if ($rootDc)
{
Write-Verbose "RootDC found, using the IP address of '$rootDc' for DNS: "
$networkAdapter.IPv4DnsServers = $rootDc.NetworkAdapters[0].Ipv4Address[0].IpAddress
}
else
{
Write-Verbose "No RootDC found, looking for FirstChildDC in the machine's domain"
$firstChildDC = Get-LabMachineDefinition -Role FirstChildDC | Where-Object DomainName -eq $machine.DomainName
if ($firstChildDC)
{
$networkAdapter.IPv4DnsServers = $firstChildDC.NetworkAdapters[0].Ipv4Address[0].IpAddress
}
else
{
Write-Warning "Automatic assignment of DNS server did not work for machine '$machine'. No domain controller could be found for domain '$($machine.DomainName)'"
}
}
}
}
#if there is a router in the network and no gateways defined, we try to set the gateway automatically. This does not
#apply to network adapters that have a gateway manually configured or set to DHCP, any network adapter on a router,