-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy path3_Deploy.ps1
More file actions
1858 lines (1632 loc) · 88.8 KB
/
3_Deploy.ps1
File metadata and controls
1858 lines (1632 loc) · 88.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
# Verify Running as Admin
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
If (-not $isAdmin) {
Write-Host "-- Restarting as Administrator" -ForegroundColor Cyan ; Start-Sleep -Seconds 1
if($PSVersionTable.PSEdition -eq "Core") {
Start-Process pwsh.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
} else {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
}
exit
}
#region Functions
. $PSScriptRoot\0_Shared.ps1 # [!build-include-inline]
. $PSScriptRoot\0_DCHydrate.ps1 # [!build-include-inline]
Function CreateUnattendFileBlob{
#Create Unattend (parameter is Blob)
param (
[parameter(Mandatory=$true)]
[string]
$Blob,
[parameter(Mandatory=$true)]
[string]
$AdminPassword,
[parameter(Mandatory=$true)]
[string]
$TimeZone,
[parameter(Mandatory=$false)]
[string]
$RunSynchronous
)
if ( Test-Path "$PSScriptRoot\Temp\unattend.xml" ) {
Remove-Item "$PSScriptRoot\Temp\unattend.xml"
}
$unattendFile = New-Item "$PSScriptRoot\Temp\unattend.xml" -type File
$fileContent = @"
<?xml version='1.0' encoding='utf-8'?>
<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<settings pass="offlineServicing">
<component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<OfflineIdentification>
<Provisioning>
<AccountData>$Blob</AccountData>
</Provisioning>
</OfflineIdentification>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAccounts>
<AdministratorPassword>
<Value>$AdminPassword</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<SkipMachineOOBE>true</SkipMachineOOBE>
<SkipUserOOBE>true</SkipUserOOBE>
</OOBE>
<TimeZone>$TimeZone</TimeZone>
</component>
</settings>
<settings pass="specialize">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
$oeminformation
<RegisteredOwner>PFE</RegisteredOwner>
<RegisteredOrganization>PFE Inc.</RegisteredOrganization>
</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>
$RunSynchronous
</RunSynchronous>
</component>
</settings>
</unattend>
"@
Set-Content $unattendFile $fileContent
#return the file object
$unattendFile
}
Function CreateUnattendFileNoDjoin{
#Create Unattend(without domain join)
param (
[parameter(Mandatory=$true)]
[string]
$ComputerName,
[parameter(Mandatory=$true)]
[string]
$AdminPassword,
[parameter(Mandatory=$true)]
[string]
$TimeZone,
[parameter(Mandatory=$false)]
[string]
$RunSynchronous,
[parameter(Mandatory=$false)]
[string]
$AdditionalAccount
)
if ( Test-Path "$PSScriptRoot\Temp\unattend.xml" ) {
Remove-Item "$PSScriptRoot\Temp\unattend.xml"
}
$unattendFile = New-Item "$PSScriptRoot\Temp\unattend.xml" -type File
$fileContent = @"
<?xml version='1.0' encoding='utf-8'?>
<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<settings pass="specialize">
<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">
<ComputerName>$Computername</ComputerName>
$oeminformation
<RegisteredOwner>PFE</RegisteredOwner>
<RegisteredOrganization>PFE Inc.</RegisteredOrganization>
</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>
$RunSynchronous
</RunSynchronous>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAccounts>
$AdditionalAccount
<AdministratorPassword>
<Value>$AdminPassword</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<SkipMachineOOBE>true</SkipMachineOOBE>
<SkipUserOOBE>true</SkipUserOOBE>
</OOBE>
<TimeZone>$TimeZone</TimeZone>
</component>
</settings>
</unattend>
"@
Set-Content $unattendFile $fileContent
#return the file object
$unattendFile
}
Function CreateUnattendFileWin2012{
#Create Unattend(traditional Djoin with username/pass)
param (
[parameter(Mandatory=$true)]
[string]
$ComputerName,
[parameter(Mandatory=$true)]
[string]
$AdminPassword,
[parameter(Mandatory=$true)]
[string]
$TimeZone,
[parameter(Mandatory=$false)]
[string]
$RunSynchronous,
[parameter(Mandatory=$true)]
[string]
$DomainName
)
if ( Test-Path "$PSScriptRoot\Temp\unattend.xml" ) {
Remove-Item "$PSScriptRoot\Temp\unattend.xml"
}
$unattendFile = New-Item "$PSScriptRoot\Temp\unattend.xml" -type File
$fileContent = @"
<?xml version='1.0' encoding='utf-8'?>
<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<settings pass="specialize">
<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">
<ComputerName>$Computername</ComputerName>
$oeminformation
<RegisteredOwner>PFE</RegisteredOwner>
<RegisteredOrganization>PFE Inc.</RegisteredOrganization>
</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>
$RunSynchronous
</RunSynchronous>
</component>
<component name="Microsoft-Windows-UnattendedJoin" 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">
<Identification>
<Credentials>
<Domain>$DomainName</Domain>
<Password>$AdminPassword</Password>
<Username>Administrator</Username>
</Credentials>
<JoinDomain>$DomainName</JoinDomain>
</Identification>
</component>
</settings>
<settings pass="oobeSystem">
<component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<UserAccounts>
<AdministratorPassword>
<Value>$AdminPassword</Value>
<PlainText>true</PlainText>
</AdministratorPassword>
</UserAccounts>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<SkipMachineOOBE>true</SkipMachineOOBE>
<SkipUserOOBE>true</SkipUserOOBE>
</OOBE>
<TimeZone>$TimeZone</TimeZone>
</component>
</settings>
</unattend>
"@
Set-Content $unattendFile $fileContent
#return the file object
$unattendFile
}
Function AdditionalLocalAccountXML{
#Creates Additional local account unattend piece
param (
[parameter(Mandatory=$true)]
[string]
$AdminPassword,
[parameter(Mandatory=$true)]
[string]
$AdditionalAdminName
)
@"
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>$AdminPassword</Value>
<PlainText>true</PlainText>
</Password>
<Description>$AdditionalAdminName admin account</Description>
<DisplayName>$AdditionalAdminName</DisplayName>
<Group>Administrators</Group>
<Name>$AdditionalAdminName</Name>
</LocalAccount>
</LocalAccounts>
"@
}
function Get-WindowsBuildNumber {
$os = Get-CimInstance -ClassName Win32_OperatingSystem
return [int]($os.BuildNumber)
}
Function Set-VMNetworkConfiguration {
#source:http://www.ravichaganti.com/blog/?p=2766 with some changes
#example use: Get-VMNetworkAdapter -VMName Demo-VM-1 -Name iSCSINet | Set-VMNetworkConfiguration -IPAddress 192.168.100.1 00 -Subnet 255.255.0.0 -DNSServer 192.168.100.101 -DefaultGateway 192.168.100.1
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,
Position=1,
ParameterSetName='DHCP',
ValueFromPipeline=$true)]
[Parameter(Mandatory=$true,
Position=0,
ParameterSetName='Static',
ValueFromPipeline=$true)]
[Microsoft.HyperV.PowerShell.VMNetworkAdapter]$NetworkAdapter,
[Parameter(Mandatory=$true,
Position=1,
ParameterSetName='Static')]
[String[]]$IPAddress=@(),
[Parameter(Mandatory=$false,
Position=2,
ParameterSetName='Static')]
[String[]]$Subnet=@(),
[Parameter(Mandatory=$false,
Position=3,
ParameterSetName='Static')]
[String[]]$DefaultGateway = @(),
[Parameter(Mandatory=$false,
Position=4,
ParameterSetName='Static')]
[String[]]$DNSServer = @(),
[Parameter(Mandatory=$false,
Position=0,
ParameterSetName='DHCP')]
[Switch]$Dhcp
)
$VM = Get-CimInstance -Namespace "root\virtualization\v2" -ClassName "Msvm_ComputerSystem" | Where-Object ElementName -eq $NetworkAdapter.VMName
$VMSettings = Get-CimAssociatedInstance -InputObject $vm -ResultClassName "Msvm_VirtualSystemSettingData" | Where-Object VirtualSystemType -EQ "Microsoft:Hyper-V:System:Realized"
$VMNetAdapters = Get-CimAssociatedInstance -InputObject $VMSettings -ResultClassName "Msvm_SyntheticEthernetPortSettingData"
$networkAdapterConfiguration = @()
foreach ($netAdapter in $VMNetAdapters) {
if ($netAdapter.ElementName -eq $NetworkAdapter.Name) {
$networkAdapterConfiguration = Get-CimAssociatedInstance -InputObject $netAdapter -ResultClassName "Msvm_GuestNetworkAdapterConfiguration"
break
}
}
$networkAdapterConfiguration.PSBase.CimInstanceProperties["IPAddresses"].Value = $IPAddress
$networkAdapterConfiguration.PSBase.CimInstanceProperties["Subnets"].Value = $Subnet
$networkAdapterConfiguration.PSBase.CimInstanceProperties["DefaultGateways"].Value = $DefaultGateway
$networkAdapterConfiguration.PSBase.CimInstanceProperties["DNSServers"].Value = $DNSServer
$networkAdapterConfiguration.PSBase.CimInstanceProperties["ProtocolIFType"].Value = 4096
if ($dhcp) {
$networkAdapterConfiguration.PSBase.CimInstanceProperties["DHCPEnabled"].Value = $true
} else {
$networkAdapterConfiguration.PSBase.CimInstanceProperties["DHCPEnabled"].Value = $false
}
$cimSerializer = [Microsoft.Management.Infrastructure.Serialization.CimSerializer]::Create()
$serializedInstance = $cimSerializer.Serialize($networkAdapterConfiguration, [Microsoft.Management.Infrastructure.Serialization.InstanceSerializationOptions]::None)
$serializedInstanceString = [System.Text.Encoding]::Unicode.GetString($serializedInstance)
$service = Get-CimInstance -ClassName "Msvm_VirtualSystemManagementService" -Namespace "root\virtualization\v2"
$setIp = Invoke-CimMethod -InputObject $service -MethodName "SetGuestNetworkAdapterConfiguration" -Arguments @{
ComputerSystem = $VM
NetworkConfiguration = @($serializedInstanceString)
}
if($setIp.ReturnValue -eq 0) { # completed
WriteInfo "`t`t Success"
} else {
# unexpected response
$setIp
}
}
function WrapProcess{
#Using this function you can run legacy program and search in output string
#Example: WrapProcess -filename fltmc.exe -arguments "attach svhdxflt e:" -outputstring "Success"
[CmdletBinding()]
[Alias()]
[OutputType([bool])]
Param (
# process name. For example fltmc.exe
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$filename,
# arguments. for example "attach svhdxflt e:"
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
$arguments,
# string to search. for example "attach svhdxflt e:"
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
$outputstring
)
Process {
$procinfo = New-Object System.Diagnostics.ProcessStartInfo
$procinfo.FileName = $filename
$procinfo.Arguments = $arguments
$procinfo.UseShellExecute = $false
$procinfo.CreateNoWindow = $true
$procinfo.RedirectStandardOutput = $true
$procinfo.RedirectStandardError = $true
# Create a process object using the startup info
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $procinfo
# Start the process
$process.Start() | Out-Null
# test if process is still running
if(!$process.HasExited){
do{
Start-Sleep 1
}until ($process.HasExited -eq $true)
}
# get output
$out = $process.StandardOutput.ReadToEnd()
if ($out.Contains($outputstring)) {
$output=$true
} else {
$output=$false
}
return, $output
}
}
function New-LinuxVM {
[cmdletbinding()]
param(
[PSObject]$VMConfig,
[PSObject]$LabConfig,
[string]$LabFolder
)
WriteInfoHighlighted "Creating VM $($VMConfig.VMName)"
WriteInfo "`t Looking for Parent Disk"
if ($VMConfig.ParentVHD){
$serverparent = Get-ChildItem "$PSScriptRoot\ParentDisks\" -Recurse | Where-Object Name -eq $VMConfig.ParentVHD
if ($serverparent -eq $null) {
WriteErrorAndExit "Server parent disk $($VMConfig.ParentVHD) not found."
}else{
WriteInfo "`t`t Server parent disk $($serverparent.Name) found"
}
}else{
WriteInfo "`t`t Server parent disk not specified. VHD will be created"
}
$VMname=$Labconfig.Prefix+$VMConfig.VMName
if ($serverparent.Extension -eq ".vhdx"){
$vhdpath="$LabFolder\VMs\$VMname\Virtual Hard Disks\$VMname.vhdx"
}elseif($serverparent.Extension -eq ".vhd"){
$vhdpath="$LabFolder\VMs\$VMname\Virtual Hard Disks\$VMname.vhd"
}else{
$vhdpath="$LabFolder\VMs\$VMname\Virtual Hard Disks\$VMname.vhdx"
}
if ($serverparent){
WriteInfo "`t Creating OS VHD from parent disk $($VMConfig.ParentVHD)"
New-VHD -ParentPath $serverparent.fullname -Path $vhdpath
}else{
WriteInfo "`t Creating blank OS VHD"
New-VHD -Path $vhdpath -SizeBytes 127GB
}
if ($VMConfig.VMVersion){
$VMTemp = New-VM -Path "$LabFolder\VMs" -Name $VMname -Generation 2 -MemoryStartupBytes $VMConfig.MemoryStartupBytes -SwitchName $SwitchName -VHDPath $vhdPath -Version $VMConfig.VMVersion
}else{
$VMTemp = New-VM -Path "$LabFolder\VMs" -Name $VMname -Generation 2 -MemoryStartupBytes $VMConfig.MemoryStartupBytes -SwitchName $SwitchName -VHDPath $vhdPath
}
#Set dynamic memory
if ($VMConfig.StaticMemory -eq $false){
WriteInfo "`t Configuring DynamicMemory"
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $true
} else {
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $false
}
$VMTemp | Get-VMNetworkAdapter | Rename-VMNetworkAdapter -NewName Management1
if ($VMTemp.AutomaticCheckpointsEnabled -eq $True){
$VMTemp | Set-VM -AutomaticCheckpointsEnabled $False
}
if ($VMConfig.SecureBoot -eq "Linux"){
WriteInfo "`t Configuring Secure Boot to Linux"
$VMTemp | Set-VMFirmware -SecureBootTemplateId ([guid]'272e7447-90a4-4563-a4b9-8e4ab00526ce')
}else{
WriteInfo "`t Disabling Secure Boot"
$VMTemp | Set-VMFirmware -EnableSecureBoot Off
}
# only Debian Buster supports Secure Boot
#$vm | Set-VMFirmware -EnableSecureBoot On -SecureBootTemplateId "272e7447-90a4-4563-a4b9-8e4ab00526ce" # -SecureBootTemplate MicrosoftUEFICertificateAuthority
Start-VM $VMTemp
# wait for the IP address
Write-Host "`t Waiting for network connectivity to the VM..." -NoNewLine
$count = 0
do {
$ip = $VMTemp | Get-VMNetworkAdapter | Select-Object -ExpandProperty IPAddresses
Start-Sleep -Seconds 1
Write-Host -ForegroundColor Gray -NoNewline "."
$count += 1
} while (-not $ip -and $count -le 60)
if(-not $ip) {
WriteErrorAndExit "Unable to detect IP for a VM $vmName"
} else {
WriteInfo "OK"
}
$sshKeyPath = $LabConfig.SshKeyPath
if(-not $sshKeyPath) {
$sshKeyPath = "$LabFolder\.ssh\lab_rsa"
}
if(-not (Test-Path $sshKeyPath)) {
WriteErrorAndExit "`t Cannot find SSH key $sshKeyPath."
}
if($LabConfig.LinuxAdminName) {
$username = $LabConfig.LinuxAdminName
} else {
$username = $LabConfig.DomainAdminName
}
$username = $username.ToLower()
# set the hostname
WriteInfo "`t Configuring guest OS hostname..."
hvc ssh -oLogLevel=ERROR -oStrictHostKeyChecking=no -i $sshKeyPath "$username@$vmName" "echo '$($LabConfig.AdminPassword)' | sudo -p '' -S sh -c 'sed -i `"s/```hostname```/$($VMConfig.VMName)/g`" /etc/hosts; hostnamectl set-hostname `"$($VMConfig.VMName)`" > /etc/hostname;'"
$linuxCommandsToExecute = ""
if(-not $VMConfig.LinuxDomainJoin -or $VMConfig.LinuxDomainJoin.ToLower() -eq "sssd") {
WriteInfo "`t Creating AD Computer object..."
Invoke-Command -VMGuid $DC.id -Credential $cred -ArgumentList $VMConfig.VMName,$path,$Labconfig -ScriptBlock {
param($Name,$path,$Labconfig);
New-ADComputer -Name $Name -Path "OU=$($Labconfig.DefaultOUName),$($Labconfig.DN)"
$password = ConvertTo-SecureString -String $Name -AsPlainText -Force
Get-ADComputer -Identity $Name | Set-ADAccountPassword -NewPassword:$password -Reset:$true
}
WriteInfo "`t Joining to AD..."
$upn = ("$(($LabConfig.DomainAdminName).ToLower())@$($LabConfig.DomainName)")
$linuxCommandsToExecute = "realm join --one-time-password $($VMConfig.VMName) $($LabConfig.DomainName); mkdir -p /home/$($upn)/.ssh/; chown $upn /home/$upn/; cp /home/$username/.ssh/authorized_keys /home/$upn/.ssh/authorized_keys; sed -i -E `"`"s/use_fully_qualified_names = .+/use_fully_qualified_names = False/g`"`" /etc/sssd/sssd.conf;"
hvc ssh -oLogLevel=ERROR -oStrictHostKeyChecking=no -i $sshKeyPath "$username@$vmName" "echo '$($LabConfig.AdminPassword)' | sudo -p '' -S sh -c '$linuxCommandsToExecute'"
}
WriteInfo "`t Shutting down VM..."
hvc ssh -oLogLevel=ERROR -oStrictHostKeyChecking=no -i $sshKeyPath "$username@$vmName" "echo '$($LabConfig.AdminPassword)' | sudo -p '' -S sh -c 'poweroff'"
# Wait for vm to shut down
$count = 0
do {
$vm = $VMTemp | Get-VM
Start-Sleep -Seconds 1
$count += 1
} while ($vm.State -ne "Off" -and $count -le 60)
if($vm.State -ne "Off") {
$VMTemp | Stop-VM
}
# return info
[PSCustomObject]@{
OSDiskPath = $vhdpath
VM = $VMTemp
}
}
Function BuildVM {
[cmdletbinding()]
param(
[PSObject]$VMConfig,
[PSObject]$LabConfig,
[string]$LabFolder
)
WriteInfoHighlighted "Creating VM $($VMConfig.VMName)"
WriteInfo "`t Looking for Parent Disk"
if ($VMConfig.ParentVHD){
$serverparent = Get-ChildItem "$PSScriptRoot\ParentDisks\" -Recurse | Where-Object Name -eq $VMConfig.ParentVHD
if ($serverparent -eq $null) {
WriteErrorAndExit "Server parent disk $($VMConfig.ParentVHD) not found."
}else{
WriteInfo "`t`t Server parent disk $($serverparent.Name) found"
}
}else{
WriteInfo "`t`t Server parent disk not specified. VHD will be created"
}
$VMname=$Labconfig.Prefix+$VMConfig.VMName
if ($serverparent.Extension -eq ".vhdx"){
$vhdpath="$LabFolder\VMs\$VMname\Virtual Hard Disks\$VMname.vhdx"
}elseif($serverparent.Extension -eq ".vhd"){
$vhdpath="$LabFolder\VMs\$VMname\Virtual Hard Disks\$VMname.vhd"
}else{
$vhdpath="$LabFolder\VMs\$VMname\Virtual Hard Disks\$VMname.vhdx"
}
if ($serverparent){
WriteInfo "`t Creating OS VHD from parent disk $($VMConfig.ParentVHD)"
New-VHD -ParentPath $serverparent.fullname -Path $vhdpath
#Get VM Version
[System.Version]$BuildVersion=(Get-WindowsImage -ImagePath $VHDPath -Index 1).Version
WriteInfo "`t VM Version is $($BuildVersion.Build).$($BuildVersion.Revision)"
}else{
WriteInfo "`t Creating blank OS VHD"
New-VHD -Path $vhdpath -SizeBytes 127GB
}
WriteInfo "`t Creating VM"
if ($VMConfig.VMVersion){
if ($VMConfig.Generation -eq 1){
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1 -Version $VMConfig.VMVersion
}else{
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2 -Version $VMConfig.VMVersion
}
}else{
if ($VMConfig.Generation -eq 1){
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1
}else{
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2
}
}
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $true
$VMTemp | Get-VMNetworkAdapter | Rename-VMNetworkAdapter -NewName Management1
if ($VMTemp.AutomaticCheckpointsEnabled -eq $True){
$VMTemp | Set-VM -AutomaticCheckpointsEnabled $False
}
$MGMTNICs=$VMConfig.MGMTNICs
If($MGMTNICs -eq $null){
$MGMTNICs = 2
}
If($MGMTNICs -gt 8){
$MGMTNICs=8
}
If($MGMTNICs -ge 2){
2..$MGMTNICs | ForEach-Object {
WriteInfo "`t Adding Network Adapter Management$_"
$VMTemp | Add-VMNetworkAdapter -Name "Management$_"
}
}
WriteInfo "`t Connecting vNIC to $switchname"
$VMTemp | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName $SwitchName
if ($LabConfig.Secureboot -eq $False) {
WriteInfo "`t Disabling Secureboot"
$VMTemp | Set-VMFirmware -EnableSecureBoot Off
}
if ($VMConfig.AdditionalNetworks -eq $True){
WriteInfo "`t Configuring Additional networks"
foreach ($AdditionalNetworkConfig in $Labconfig.AdditionalNetworksConfig){
WriteInfo "`t`t Adding Adapter $($AdditionalNetworkConfig.NetName) with IP $($AdditionalNetworkConfig.NetAddress)$global:IP"
$VMTemp | Add-VMNetworkAdapter -SwitchName $SwitchName -Name $AdditionalNetworkConfig.NetName
$VMTemp | Get-VMNetworkAdapter -Name $AdditionalNetworkConfig.NetName | Set-VMNetworkConfiguration -IPAddress "$($AdditionalNetworkConfig.NetAddress)$global:IP" -Subnet $AdditionalNetworkConfig.Subnet
if($AdditionalNetworkConfig.NetVLAN -ne 0){ $VMTemp | Get-VMNetworkAdapter -Name $AdditionalNetworkConfig.NetName | Set-VMNetworkAdapterVlan -VlanId $AdditionalNetworkConfig.NetVLAN -Access }
}
$global:IP++
}
if($VMConfig.AdditionalNetworkAdapters) {
$networks = $VMConfig.AdditionalNetworkAdapters
if($networks -isnot [array]) {
$networks = @($networks)
}
foreach ($network in $networks) {
$switch = Get-VMSwitch -Name $network.VirtualSwitchName -ErrorAction SilentlyContinue
if(-not $switch) {
WriteErrorAndExit "Hyper-V switch $($network.VirtualSwitchName) not found."
}
$adapter = $vmtemp | Add-VMNetworkAdapter -SwitchName $network.VirtualSwitchName -Passthru
if($network.Mac -and $network.Mac -match "^([0-9A-F][0-9A-F]-){5}[0-9A-F][0-9A-F]$") {
$adapter | Set-VMNetworkAdapter -StaticMacAddress $network.Mac
}
if($network.VlanId -and $network.VlanId -ne 0) {
$adapter | Set-VMNetworkAdapterVlan -VlanId $network.VlanId -Access
}
if($network.IpConfiguration -and $network.IpConfiguration -ne "DHCP" -and $network.IpConfiguration -is [Hashtable]) {
$adapter | Set-VMNetworkConfiguration -IPAddress $network.IpConfiguration.IpAddress -Subnet $network.IpConfiguration.Subnet
}
}
}
#Generate DSC Config
if ($VMConfig.DSCMode -eq 'Pull'){
WriteInfo "`t Setting DSC Mode to Pull"
PullClientConfig -ComputerName $VMConfig.VMName -DSCConfig $VMConfig.DSCConfig -OutputPath "$PSScriptRoot\temp\dscconfig" -DomainName $LabConfig.DomainName
}
#configure nested virt
if ($VMConfig.NestedVirt -eq $True){
WriteInfo "`t Enabling NestedVirt"
$VMTemp | Set-VMProcessor -ExposeVirtualizationExtensions $true
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $False
}
#configure vTPM
if ($VMConfig.vTPM -eq $True){
if ($VMConfig.Generation -eq 1){
WriteError "`t vTPM requested. But vTPM is not compatible with Generation 1"
}else{
WriteInfo "`t Enabling vTPM"
$keyprotector = New-HgsKeyProtector -Owner $guardian -AllowUntrustedRoot
Set-VMKeyProtector -VM $VMTemp -KeyProtector $keyprotector.RawData
Enable-VMTPM -VM $VMTemp
}
}
#configure secure boot
if ($VMConfig.SecureBoot -eq "Linux"){
WriteInfo "`t Configuring Secure Boot to Linux"
$VMTemp | Set-VMFirmware -SecureBootTemplateId ([guid]'272e7447-90a4-4563-a4b9-8e4ab00526ce')
}elseif ($VMConfig.SecureBoot -eq "Disabled"){
WriteInfo "`t Disabling Secure Boot"
$VMTemp | Set-VMFirmware -EnableSecureBoot Off
}
#set MemoryMinimumBytes
if ($VMConfig.MemoryMinimumBytes -ne $null){
WriteInfo "`t Configuring MemoryMinimumBytes to $($VMConfig.MemoryMinimumBytes/1MB)MB"
if ($VMConfig.NestedVirt){
"`t`t Skipping! NestedVirt configured"
}else{
Set-VM -VM $VMTemp -MemoryMinimumBytes $VMConfig.MemoryMinimumBytes
}
}
#Set static Memory
if ($VMConfig.StaticMemory -eq $true){
WriteInfo "`t Configuring StaticMemory"
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $false
}
#configure number of processors
if ($VMConfig.VMProcessorCount){
if ($VMConfig.VMProcessorCount -eq "Max"){
if ($NumberOfLogicalProcessors -gt 64){
WriteInfo "`t Processors Count $NumberOfLogicalProcessors and Max is specified. Configuring VM Processor Count to 64"
$VMTemp | Set-VMProcessor -Count 64
}else{
WriteInfo "`t Configuring VM Processor Count to Max ($NumberOfLogicalProcessors)"
$VMTemp | Set-VMProcessor -Count $NumberOfLogicalProcessors
}
}elseif ($VMConfig.VMProcessorCount -le $NumberOfLogicalProcessors){
WriteInfo "`t Configuring VM Processor Count to $($VMConfig.VMProcessorCount)"
$VMTemp | Set-VMProcessor -Count $VMConfig.VMProcessorCount
}else{
WriteError "`t`t Number of processors specified in VMProcessorCount is greater than Logical Processors available in Host!"
WriteInfo "`t`t Number of logical Processors in Host $NumberOfLogicalProcessors"
WriteInfo "`t`t Number of Processors provided in labconfig $($VMConfig.VMProcessorCount)"
WriteInfo "`t`t Will configure maximum processors possible instead ($NumberOfLogicalProcessors)"
$VMTemp | Set-VMProcessor -Count $NumberOfLogicalProcessors
}
}else{
$VMTemp | Set-VMProcessor -Count 2
}
#Disable Time Integration Components
If ($VMConfig.DisableTimeIC){
WriteInfo "`t`t Disabling Time Synchronization Integration Service"
$VMTemp | Disable-VMIntegrationService -Name "Time Synchronization"
}
$Name=$VMConfig.VMName
#add run synchronous commands
WriteInfo "`t Adding Sync Commands"
$RunSynchronous=""
if ($VMConfig.EnableWinRM){
$RunSynchronous+=@'
<RunSynchronousCommand wcm:action="add">
<Path>cmd.exe /c winrm quickconfig -q -force</Path>
<Description>enable winrm</Description>
<Order>1</Order>
</RunSynchronousCommand>
'@
WriteInfo "`t`t WinRM will be enabled"
}
if ($VMConfig.DisableWCF){
$RunSynchronous+=@'
<RunSynchronousCommand wcm:action="add">
<Path>reg add HKLM\Software\Policies\Microsoft\Windows\CloudContent /v DisableWindowsConsumerFeatures /t REG_DWORD /d 1 /f</Path>
<Description>disable consumer features</Description>
<Order>2</Order>
</RunSynchronousCommand>
'@
WriteInfo "`t`t WCF will be disabled"
}
if ($VMConfig.CustomPowerShellCommands){
$Order=3
foreach ($CustomPowerShellCommand in $VMConfig.CustomPowerShellCommands){
$RunSynchronous+=@"
<RunSynchronousCommand wcm:action="add">
<Path>powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -Command "$CustomPowerShellCommand"</Path>
<Description>run custom powershell</Description>
<Order>$Order</Order>
</RunSynchronousCommand>
"@
$Order++
}
WriteInfo "`t`t Custom PowerShell command will be added"
}
if (-not $RunSynchronous){
WriteInfo "`t`t No sync commands requested"
}
if ($BuildVersion.Build -ge 17763){
$oeminformation=@"
<OEMInformation>
<SupportProvider>MSLab</SupportProvider>
<SupportURL>https://aka.ms/mslab</SupportURL>
</OEMInformation>
"@
}else{
$oeminformation=$null
}
#configure native VLAN and AllowedVLANs
$AllowedVLANs=$($LabConfig.AllowedVLANs)
WriteInfo "`t`t Subnet ID is 0 with NativeVLAN 0. AllowedVlanIDList is $($LabConfig.AllowedVLANs)"
$VMTemp | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId 0 -AllowedVlanIdList "$AllowedVLANs"
if ($serverparent){
#Create Unattend file if there was server parent disk. If not, blank was created and it does not make sense to create answer file
if ($VMConfig.Unattend -eq "NoDjoin" -or $VMConfig.SkipDjoin){
WriteInfo "`t Skipping Djoin"
if ($VMConfig.AdditionalLocalAdmin){
WriteInfo "`t Additional Local Admin $($VMConfig.AdditionalLocalAdmin) will be added"
$AdditionalLocalAccountXML=AdditionalLocalAccountXML -AdditionalAdminName $VMConfig.AdditionalLocalAdmin -AdminPassword $LabConfig.AdminPassword
$unattendfile=CreateUnattendFileNoDjoin -ComputerName $Name -AdminPassword $LabConfig.AdminPassword -RunSynchronous $RunSynchronous -AdditionalAccount $AdditionalLocalAccountXML -TimeZone $TimeZone
}else{
$unattendfile=CreateUnattendFileNoDjoin -ComputerName $Name -AdminPassword $LabConfig.AdminPassword -RunSynchronous $RunSynchronous -TimeZone $TimeZone
}
}elseif($VMConfig.Win2012Djoin -or $VMConfig.Unattend -eq "DjoinCred"){
WriteInfoHighlighted "`t Creating Unattend with win2012-ish domain join"
$unattendfile=CreateUnattendFileWin2012 -ComputerName $Name -AdminPassword $LabConfig.AdminPassword -DomainName $Labconfig.DomainName -RunSynchronous $RunSynchronous -TimeZone $TimeZone
}elseif($VMConfig.Unattend -eq "DjoinBlob" -or -not ($VMConfig.Unattend)){
WriteInfoHighlighted "`t Creating Unattend with djoin blob"
$path="c:\$vmname.txt"
Invoke-Command -VMGuid $DC.id -Credential $cred -ScriptBlock {param($Name,$path,$Labconfig); djoin.exe /provision /domain $labconfig.DomainNetbiosName /machine $Name /savefile $path /machineou "OU=$($Labconfig.DefaultOUName),$($Labconfig.DN)"} -ArgumentList $Name,$path,$Labconfig
$blob=Invoke-Command -VMGuid $DC.id -Credential $cred -ScriptBlock {param($path); get-content $path} -ArgumentList $path
Invoke-Command -VMGuid $DC.id -Credential $cred -ScriptBlock {param($path); Remove-Item $path} -ArgumentList $path
$unattendfile=CreateUnattendFileBlob -Blob $blob.Substring(0,$blob.Length-1) -AdminPassword $LabConfig.AdminPassword -RunSynchronous $RunSynchronous -TimeZone $TimeZone
}elseif($VMConfig.Unattend -eq "None"){
$unattendFile=$Null
}
#adding unattend to VHD
if ($unattendFile){
WriteInfo "`t Adding unattend to VHD"
Mount-WindowsImage -Path $mountdir -ImagePath $VHDPath -Index 1
Use-WindowsUnattend -Path $mountdir -UnattendPath $unattendFile
#&"$PSScriptRoot\Tools\dism\dism" /mount-image /imagefile:$vhdpath /index:1 /MountDir:$mountdir
#&"$PSScriptRoot\Tools\dism\dism" /image:$mountdir /Apply-Unattend:$unattendfile
New-item -type directory "$mountdir\Windows\Panther" -ErrorAction Ignore
Copy-Item $unattendfile "$mountdir\Windows\Panther\unattend.xml"
}
if ($VMConfig.DSCMode -eq 'Pull'){
WriteInfo "`t Adding metaconfig.mof to VHD"
Copy-Item "$PSScriptRoot\temp\dscconfig\$name.meta.mof" -Destination "$mountdir\Windows\system32\Configuration\metaconfig.mof"
}
if ($unattendFile){
Dismount-WindowsImage -Path $mountdir -Save
#&"$PSScriptRoot\Tools\dism\dism" /Unmount-Image /MountDir:$mountdir /Commit
}
}
#add toolsdisk
if ($VMConfig.AddToolsVHD -eq $True){
$VHD=New-VHD -ParentPath "$($toolsparent.fullname)" -Path "$LabFolder\VMs\$VMname\Virtual Hard Disks\tools.vhdx"
WriteInfoHighlighted "`t Adding Virtual Hard Disk $($VHD.Path)"
$VMTemp | Add-VMHardDiskDrive -Path $vhd.Path
}
#add ISO
if ($VMConfig.AttachISO){
if (-not ($VMTemp | Get-VMDvdDrive)){
WriteInfoHighlighted "`t Adding ISO $($VMConfig.AttachISO)"
$DVD=$VMTemp | Add-VMDvdDrive -Path "$PSScriptRoot\ParentDisks\$($VMConfig.AttachISO)" -Passthru
$VMTemp | Set-VMFirmware -FirstBootDevice $DVD
}
}
# return info
[PSCustomObject]@{
OSDiskPath = $vhdpath
VM = $VMTemp
}
}
#endregion
#region Initialization
Start-Transcript -Path "$PSScriptRoot\Deploy.log"
$StartDateTime = Get-Date
WriteInfoHighlighted "Script started at $StartDateTime"
WriteInfo "`nMSLab Version $mslabVersion"
##Load LabConfig....
. "$PSScriptRoot\LabConfig.ps1"
# Telemetry
if(-not (Get-TelemetryLevel)) {
$telemetryLevel = Read-TelemetryLevel
$LabConfig.TelemetryLevel = $telemetryLevel
$LabConfig.TelemetryLevelSource = "Prompt"
$promptShown = $true
}
if((Get-TelemetryLevel) -in $TelemetryEnabledLevels) {
if(-not $promptShown) {
WriteInfo "Telemetry is set to $(Get-TelemetryLevel) level from $(Get-TelemetryLevelSource)"
}
Send-TelemetryEvent -Event "Deploy.Start" -NickName $LabConfig.TelemetryNickName | Out-Null
}
#endregion
#region Set variables
If (!$LabConfig.DomainNetbiosName){
$LabConfig.DomainNetbiosName="Corp"
}
If (!$LabConfig.DomainName){
$LabConfig.DomainName="Corp.contoso.com"
}
If (!$LabConfig.DefaultOUName){
$LabConfig.DefaultOUName="Workshop"
}
if (!$Labconfig.AllowedVLANs){
$Labconfig.AllowedVLANs="1-10"
}
$DN=$null
$LabConfig.DomainName.Split(".") | ForEach-Object {
$DN+="DC=$_,"
}
$LabConfig.DN=$DN.TrimEnd(",")
$global:IP=1
if (!$LabConfig.Prefix){
$labconfig.prefix="$($PSScriptRoot | Split-Path -Leaf)-"
}
if (!$LabConfig.SwitchName){
$LabConfig.SwitchName = 'LabSwitch'
}
If (!$LabConfig.DHCPscope){
$LabConfig.DHCPscope="10.0.0.0"
}
if (!$LabConfig.DHCPscopeState){
$LabConfig.DHCPscopeState = 'Active'
}
WriteInfoHighlighted "List of variables used"
WriteInfo "`t Prefix used in lab is $($labconfig.prefix)"
$SwitchName=($labconfig.prefix+$LabConfig.SwitchName)
WriteInfo "`t Switchname is $SwitchName"
WriteInfo "`t Workdir is $PSScriptRoot"
$LABfolder="$PSScriptRoot\LAB"
WriteInfo "`t LabFolder is $LabFolder"
$LABfolderDrivePath=$LABfolder.Substring(0,3)
$ExternalSwitchName="$($Labconfig.Prefix)$($LabConfig.Switchname)-External"
#Grab TimeZone
$TimeZone=(Get-TimeZone).id
#Grab number of processors
Get-CimInstance -ClassName "win32_processor" | ForEach-Object { $global:NumberOfLogicalProcessors += $_.NumberOfEnabledCore }
#Calculate highest VLAN (for additional subnets)
[int]$HighestVLAN=$LabConfig.AllowedVLANs -split "," -split "-" | Select-Object -Last 1
#endregion
#region Some Additional checks and prereqs configuration
# Checking if not running in root folder
if (($PSScriptRoot).Length -eq 3) {
WriteErrorAndExit "`t MSLab canot run in root folder. Please put MSLab scripts into a folder. Exiting"
}
# Checking for Compatible OS
WriteInfoHighlighted "Checking if OS is Windows 10 1511 (10586)/Server 2016 or newer"
$BuildNumber=Get-WindowsBuildNumber
if ($BuildNumber -ge 10586){
WriteSuccess "`t OS is Windows 10 1511 (10586)/Server 2016 or newer"
}else{
WriteErrorAndExit "`t Windows 10/ Server 2016 not detected. Exiting"
}
# Checking for NestedVirt
if ($LABConfig.VMs.NestedVirt -contains $True){
$BuildNumber=Get-WindowsBuildNumber
if ($BuildNumber -ge 14393){
WriteSuccess "`t Windows is build greater than 14393. NestedVirt will work"