forked from jamesstringerparsec/Easy-GPU-PV
-
Notifications
You must be signed in to change notification settings - Fork 6
/
GPUP-management.ps1
4310 lines (3998 loc) · 198 KB
/
GPUP-management.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
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
#========================================================================
$Global:VM
$Global:VHD
$Global:ServerOS
$Global:StateWasRunning
#========================================================================
#========================================================================
$params = @{
GPUName = ""
DriveLetter = ""
GPUDedicatedResourcePercentage = 100
VMName = ""
SourcePath = ""
Edition = ""
VhdFormat = "VHDX"
DiskLayout = "UEFI"
SizeBytes = 127GB
MemoryAmount = 4GB
MemoryMaximum = 32GB
DynamicMemoryEnabled = $true
CPUCores = 4
NetworkSwitch = "Default Switch"
VMPath = ""
VHDPath = ""
Team_ID = ""
Key = ""
Username = ""
Password = ""
Autologon = $true
RDP = $true
Parsec = $true
CopyRegionalSettings = $true
ParsecVDD = $false
DisableHVDD = $false
NumLock = $true
}
#========================================================================
#========================================================================
[xml]$unattend = @"
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-International-Core-WinPE" 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">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<InputLocale>0409:00000409</InputLocale>
<SystemLocale>en-US</SystemLocale>
<UILanguage>en-US</UILanguage>
<UILanguageFallback>en-US</UILanguageFallback>
<UserLocale>en-US</UserLocale>
</component>
<component name="Microsoft-Windows-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">
<DiskConfiguration>
<Disk wcm:action="add">
<DiskID>0</DiskID>
<WillWipeDisk>true</WillWipeDisk>
<CreatePartitions>
<!-- Windows RE Tools partition -->
<CreatePartition wcm:action="add">
<Order>1</Order>
<Type>Primary</Type>
<Size>300</Size>
</CreatePartition>
<!-- System partition (ESP) -->
<CreatePartition wcm:action="add">
<Order>2</Order>
<Type>EFI</Type>
<Size>100</Size>
</CreatePartition>
<!-- Microsoft reserved partition (MSR) -->
<CreatePartition wcm:action="add">
<Order>3</Order>
<Type>MSR</Type>
<Size>128</Size>
</CreatePartition>
<!-- Windows partition -->
<CreatePartition wcm:action="add">
<Order>4</Order>
<Type>Primary</Type>
<Extend>true</Extend>
</CreatePartition>
</CreatePartitions>
<ModifyPartitions>
<!-- Windows RE Tools partition -->
<ModifyPartition wcm:action="add">
<Order>1</Order>
<PartitionID>1</PartitionID>
<Label>WINRE</Label>
<Format>NTFS</Format>
<TypeID>DE94BBA4-06D1-4D40-A16A-BFD50179D6AC</TypeID>
</ModifyPartition>
<!-- System partition (ESP) -->
<ModifyPartition wcm:action="add">
<Order>2</Order>
<PartitionID>2</PartitionID>
<Label>System</Label>
<Format>FAT32</Format>
</ModifyPartition>
<!-- MSR partition does not need to be modified -->
<ModifyPartition wcm:action="add">
<Order>3</Order>
<PartitionID>3</PartitionID>
</ModifyPartition>
<!-- Windows partition -->
<ModifyPartition wcm:action="add">
<Order>4</Order>
<PartitionID>4</PartitionID>
<Label>OS</Label>
<Letter>C</Letter>
<Format>NTFS</Format>
</ModifyPartition>
</ModifyPartitions>
</Disk>
</DiskConfiguration>
<ImageInstall>
<OSImage>
<InstallTo>
<DiskID>0</DiskID>
<PartitionID>4</PartitionID>
</InstallTo>
<InstallToAvailablePartition>false</InstallToAvailablePartition>
</OSImage>
</ImageInstall>
<UserData>
<ProductKey>
<!-- Do not uncomment the Key element if you are using trial ISOs -->
<!-- You must uncomment the Key element (and optionally insert your own key) if you are using retail or volume license ISOs -->
<Key>
</Key>
<WillShowUI>Never</WillShowUI>
</ProductKey>
<AcceptEula>true</AcceptEula>
<FullName>GPU-P</FullName>
<Organization>
</Organization>
</UserData>
</component>
</settings>
<settings pass="offlineServicing">
<component name="Microsoft-Windows-LUA-Settings" 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">
<EnableLUA>true</EnableLUA>
</component>
</settings>
<settings pass="generalize">
<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-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>
<UILanguageFallback>en-US</UILanguageFallback>
<UserLocale>en-US</UserLocale>
</component>
<component name="Microsoft-Windows-Security-SPP-UX" 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">
<SkipAutoActivation>true</SkipAutoActivation>
</component>
<component name="Microsoft-Windows-SQMApi" 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">
<CEIPEnabled>0</CEIPEnabled>
</component>
<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>GPUP122</ComputerName>
<ProductKey>W269N-WFGWX-YVC9B-4J6C9-T83GX</ProductKey>
</component>
</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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<AutoLogon>
<Password>
<Value>CoolestPassword!</Value>
<PlainText>true</PlainText>
</Password>
<Enabled>true</Enabled>
<Username>GPUVM</Username>
</AutoLogon>
<OOBE>
<HideEULAPage>true</HideEULAPage>
<HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>
<HideOnlineAccountScreens>true</HideOnlineAccountScreens>
<HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE>
<NetworkLocation>Home</NetworkLocation>
<SkipUserOOBE>true</SkipUserOOBE>
<SkipMachineOOBE>true</SkipMachineOOBE>
<ProtectYourPC>1</ProtectYourPC>
</OOBE>
<Display>
<ColorDepth>32</ColorDepth>
<HorizontalResolution>1920</HorizontalResolution>
<RefreshRate>60</RefreshRate>
<VerticalResolution>1080</VerticalResolution>
</Display>
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>
<Value>CoolestPassword!</Value>
<PlainText>true</PlainText>
</Password>
<Description>
</Description>
<DisplayName>GPUVM</DisplayName>
<Group>Administrators</Group>
<Name>GPUVM</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
<RegisteredOrganization>
</RegisteredOrganization>
<RegisteredOwner>GPU-P</RegisteredOwner>
<DisableAutoDaylightTimeSet>false</DisableAutoDaylightTimeSet>
<FirstLogonCommands>
<SynchronousCommand wcm:action="add">
<Description>Allow Scripts</Description>
<Order>1</Order>
<CommandLine>reg add HKLM\Software\Policies\Microsoft\Windows\Powershell</CommandLine>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Allow Scripts</Description>
<Order>2</Order>
<CommandLine>reg add HKLM\Software\Policies\Microsoft\Windows\Powershell /v ExecutionPolicy /t REG_SZ /d Unrestricted</CommandLine>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Description>Allow Scripts</Description>
<Order>3</Order>
<CommandLine>reg add HKLM\Software\Policies\Microsoft\Windows\Powershell /v EnableScripts /t REG_DWORD /d 1</CommandLine>
<RequiresUserInput>false</RequiresUserInput>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<Order>4</Order>
<RequiresUserInput>false</RequiresUserInput>
<CommandLine>cmd /C wmic useraccount where name="GPU-P" set PasswordExpires=false</CommandLine>
<Description>Password Never Expires</Description>
</SynchronousCommand>
</FirstLogonCommands>
<TimeZone>GTB Standard Time</TimeZone>
</component>
</settings>
</unattend>
"@
#========================================================================
#========================================================================
$ParsecLnk = (
31, 139, 8, 0, 0, 0, 0, 0, 0, 10, 237, 85, 95, 72, 83, 97, 20, 63, 179, 85, 46, 77, 39, 91, 98, 86, 186, 210, 201, 178, 156, 155, 210, 191, 129,
53, 81, 116, 90, 185, 235, 102, 217, 195, 165, 156, 219, 77, 23, 51, 215, 238, 130, 65, 80, 20, 244, 16, 44, 48, 168, 160, 208, 208, 176, 36, 208, 7, 19, 21,
31, 76, 133, 210, 183, 24, 138, 253, 51, 194, 215, 140, 16, 95, 194, 222, 58, 231, 219, 157, 179, 165, 152, 208, 147, 244, 93, 206, 249, 190, 123, 254, 254, 190, 243,
125, 231, 222, 83, 0, 32, 83, 199, 33, 7, 24, 101, 28, 202, 102, 204, 241, 160, 161, 85, 246, 228, 227, 19, 227, 211, 178, 92, 197, 181, 195, 159, 39, 166, 101,
145, 119, 75, 226, 22, 102, 40, 11, 219, 47, 141, 43, 50, 53, 100, 114, 179, 214, 144, 102, 206, 228, 86, 62, 253, 16, 15, 7, 12, 134, 182, 157, 144, 95, 98,
226, 99, 76, 105, 4, 193, 200, 230, 60, 78, 61, 156, 2, 156, 205, 90, 110, 43, 190, 142, 34, 63, 40, 64, 14, 243, 175, 196, 170, 135, 57, 164, 211, 163, 77,
95, 134, 252, 183, 132, 149, 140, 203, 191, 42, 129, 3, 31, 52, 67, 3, 114, 7, 52, 33, 236, 50, 112, 131, 7, 4, 16, 81, 111, 70, 222, 136, 107, 15, 62,
133, 80, 0, 122, 112, 177, 245, 65, 200, 195, 55, 35, 28, 129, 163, 12, 67, 26, 212, 72, 88, 244, 92, 109, 11, 198, 116, 248, 68, 193, 9, 112, 92, 66, 146,
203, 85, 5, 73, 67, 72, 78, 247, 109, 71, 30, 46, 88, 116, 140, 157, 173, 69, 36, 14, 68, 33, 98, 62, 116, 133, 84, 168, 199, 28, 84, 42, 29, 215, 122,
75, 3, 94, 22, 211, 165, 23, 2, 2, 88, 164, 184, 164, 201, 229, 172, 65, 138, 219, 221, 65, 187, 219, 181, 66, 157, 188, 203, 226, 186, 112, 15, 2, 4, 144,
0, 210, 145, 106, 144, 118, 75, 149, 161, 57, 95, 242, 177, 35, 169, 144, 54, 33, 105, 102, 126, 118, 42, 113, 182, 218, 1, 15, 130, 243, 53, 55, 248, 28, 77,
154, 50, 183, 71, 16, 249, 240, 78, 249, 229, 224, 88, 157, 244, 192, 175, 193, 87, 175, 59, 233, 162, 136, 249, 85, 240, 167, 65, 9, 152, 214, 21, 39, 107, 221,
30, 43, 103, 206, 198, 195, 83, 0, 180, 223, 195, 154, 24, 237, 156, 253, 187, 97, 248, 83, 9, 220, 41, 239, 90, 12, 169, 58, 197, 139, 251, 174, 162, 220, 69,
69, 204, 36, 3, 36, 186, 64, 20, 194, 207, 18, 95, 198, 148, 58, 9, 202, 25, 22, 156, 82, 240, 120, 37, 9, 78, 24, 70, 49, 166, 246, 66, 41, 74, 252,
72, 60, 216, 208, 143, 180, 110, 244, 110, 136, 129, 185, 127, 233, 160, 123, 36, 64, 134, 5, 237, 224, 124, 121, 186, 242, 217, 66, 92, 93, 240, 201, 183, 110, 178,
216, 22, 1, 148, 16, 115, 35, 162, 247, 1, 96, 7, 82, 50, 45, 204, 196, 10, 198, 111, 190, 31, 153, 146, 145, 48, 49, 162, 133, 47, 111, 169, 145, 88, 82,
121, 36, 36, 105, 195, 136, 61, 136, 208, 201, 80, 187, 217, 78, 195, 78, 73, 177, 33, 105, 217, 33, 129, 125, 126, 201, 169, 43, 122, 48, 153, 210, 255, 14, 70,
173, 31, 211, 66, 183, 81, 158, 17, 137, 108, 66, 250, 119, 149, 226, 255, 56, 9, 126, 213, 82, 0, 28, 147, 0, 246, 166, 54, 149, 246, 220, 245, 90, 186, 44,
102, 125, 103, 81, 32, 184, 7, 229, 141, 100, 96, 65, 170, 238, 173, 19, 109, 63, 156, 21, 253, 109, 241, 134, 236, 71, 137, 75, 31, 24, 53, 54, 206, 86, 188,
35, 90, 169, 93, 88, 183, 104, 87, 108, 151, 13, 63, 180, 49, 29, 23, 237, 55, 237, 95, 118, 220, 255, 177, 17, 6, 253, 67, 54, 99, 79, 228, 224, 60, 132,
68, 255, 27, 252, 26, 181, 15, 56, 207, 183, 140, 140, 85, 85, 188, 108, 21, 6, 11, 166, 38, 211, 73, 87, 135, 132, 45, 212, 126, 78, 242, 13, 120, 197, 60,
227, 161, 104, 172, 69, 168, 159, 78, 82, 36, 87, 6, 249, 215, 254, 217, 27, 213, 23, 84, 89, 47, 38, 18, 10, 231, 82, 134, 246, 182, 14, 132, 222, 156, 188,
191, 150, 158, 98, 252, 2, 171, 79, 220, 238, 187, 8, 0, 0
)
#========================================================================
#========================================================================
function Write-W2VInfo {
# Function to make the Write-Host output a bit prettier.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[object]
[ValidateNotNullOrEmpty()]$Object,
[bool]$NoNewline,
[Object]$Separator,
[ConsoleColor]$ForegroundColor,
[ConsoleColor]$BackgroundColor
)
$PSBoundParameters.Object = "INFO: $($Object)"
Write-Host @PSBoundParameters
}
#========================================================================
#========================================================================
function Write-W2VInProgress {
# Function to make the Write-Host output a bit prettier.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[object]
[ValidateNotNullOrEmpty()]$Object,
[Object]$Separator,
[ConsoleColor]$ForegroundColor,
[ConsoleColor]$BackgroundColor
)
if ($Global:W2VInProgressCounter++ -eq 10) { $Global:W2VInProgressCounter = 0 }
$PSBoundParameters.NoNewLine = $true
$PSBoundParameters.Object = "$($Object) $(`".`" * $Global:W2VInProgressCounter)"
Write-Host @PSBoundParameters
}
#========================================================================
#========================================================================
function Set-W2VItemProperty {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string[]]$Path,
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[Object]$Value,
[switch]$Force,
[string]$Filter,
[string[]]$Include,
[string[]]$Exclude,
[pscredential]$Credential,
[string]$Type,
[string]$PropertyType,
[object]$CommonParameters
)
if ((Test-Path $path) -eq $false) {
New-Item $path -Force
}
if ((Get-ItemProperty -path $path -name $Name -ErrorAction SilentlyContinue).Count -eq 0) {
if ($PSBoundParameters.Type.Length -ne 0) {
if ($PSBoundParameters.PropertyType.Length -eq 0) {
$PSBoundParameters.PropertyType = $PSBoundParameters.Type
}
$PSBoundParameters.Remove('Type')
}
$null = New-ItemProperty @PSBoundParameters
} else {
if ($PSBoundParameters.PropertyType.Length -ne 0) {
if ($PSBoundParameters.Type.Length -eq 0) {
$PSBoundParameters.Type = $PSBoundParameters.PropertyType
}
$PSBoundParameters.Remove('PropertyType')
}
$null = Set-ItemProperty @PSBoundParameters
}
}
#========================================================================
#========================================================================
function Is-Administrator {
$CurrentUser = [Security.Principal.WindowsIdentity]::GetCurrent();
$IsAdmin = (New-Object Security.Principal.WindowsPrincipal $CurrentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if ($IsAdmin -eq $false) {
Write-Warning "Administrator rights are required to run the script."
}
return $IsAdmin
}
#========================================================================
#========================================================================
function Get-ISOWindowsEditions {
param (
[string]$DriveLetter
)
$WinImages = Get-windowsimage -ImagePath "$($DriveLetter):\sources\install.wim"
if ($WinImages.Count -eq 0) {
return $null
}
Write-Host "Printing Windows editions on the selected disk image... It may take a while..." -ForegroundColor Yellow
$Report = @()
Write-Host "Index Edition"
Write-Host "===== ======="
foreach ($WinImage in $WinImages) {
$curImage=Get-WindowsImage -ImagePath "$($DriveLetter):\sources\install.wim" -Index $WinImage.ImageIndex
$objImage = [PSCustomObject]@{
Index = $curImage.ImageIndex
Edition = $curImage.ImageName
Version = $curImage.Version
}
Write-Host "$($curImage.ImageIndex): $($curImage.ImageName)"
$Report += $objImage
}
return $Report
}
#========================================================================
#========================================================================
function Dismount-ISO {
param (
[string]$SourcePath
)
$disk = Get-Volume | Where-Object {$_.DriveType -eq "CD-ROM"} | select *
Foreach ($d in $disk) {
Dismount-DiskImage -ImagePath $sourcePath -ErrorAction SilentlyContinue
}
}
#========================================================================
#========================================================================
function Mount-ISOReliable {
param (
[string]$SourcePath
)
$mountResult = Mount-DiskImage -ImagePath $SourcePath
$delay = 0
do {
if ($delay -gt 15) {
function Get-NewDriveLetter {
$UsedDriveLetters = ((Get-Volume).DriveLetter) -join ""
do { $DriveLetter = (65..90)| Get-Random | % {[char]$_} }
Until (!$UsedDriveLetters.Contains("$DriveLetter"))
}
$DriveLetter = "$(Get-NewDriveLetter):"
Get-WmiObject -Class Win32_volume | Where-Object {$_.Label -eq "CCCOMA_X64FRE_EN-US_DV9"} | Set-WmiInstance -Arguments @{DriveLetter="$driveletter"}
}
Start-Sleep -s 1
$delay++
} until (($mountResult | Get-Volume).DriveLetter -ne $NULL)
return ($mountResult | Get-Volume).DriveLetter
}
#========================================================================
#========================================================================
function ConcatenateVHDPath {
param(
[string]$VHDPath,
[string]$VMName
)
if ($VHDPath[-1] -eq '\') {
"$($VHDPath)$($VMName)\$($VMName).vhdx"
} else {
"$($VHDPath)\$($VMName)\$($VMName).vhdx"
}
}
#========================================================================
#========================================================================
function SmartExit {
param (
[switch]$NoHalt,
[string]$ExitReason
)
Set-PSDebug -Off
if (($host.name -eq 'Windows PowerShell ISE Host') -or ($host.Name -eq 'Visual Studio Code Host')) {
Write-Host $ExitReason
Exit $null
} else{
if ($NoHalt) {
Write-Host $ExitReason
Exit $null
} else {
Write-Host $ExitReason
Read-host -Prompt "Press any key to Exit..."
Exit $null
}
}
}
#========================================================================
#========================================================================
function New-GPUEnabledVM {
param(
[string]$DriveLetter,
[int64]$SizeBytes,
[int]$Edition,
[string]$VhdFormat,
[string]$VMPath,
[string]$VhdPath,
[string]$VMName,
[string]$DiskLayout,
[int64]$MemoryAmount,
[int64]$MemoryMaximum,
[boolean]$DynamicMemoryEnabled,
[int]$CPUCores,
[string]$NetworkSwitch,
[string]$GPUName,
[float]$GPUDedicatedResourcePercentage,
[string]$SourcePath,
[string]$Team_ID,
[string]$Key,
[string]$username,
[string]$password,
[string]$autologon,
[bool]$RDP,
[bool]$Parsec,
[bool]$CopyRegionalSettings,
[bool]$ParsecVDD,
[bool]$DisableHVDD,
[bool]$NumLock
)
$VHDPath = ConcatenateVHDPath -VHDPath $VHDPath -VMName $VMName
if ($(Get-VM -Name $VMName -ErrorAction SilentlyContinue) -ne $NULL) {
SmartExit -ExitReason "Virtual Machine already exists with name $VMName, please delete existing VM or change VMName"
}
if (Test-Path $vhdPath) {
SmartExit -ExitReason "Virtual Machine Disk already exists at $vhdPath, please delete existing VHDX or change VMName"
}
Write-Host "Virtual Machine is creating... It may take a long time..." -ForegroundColor Yellow
$unattendPath = Modify-AutoUnattend -username "$username" -password "$password" -autologon $autologon -hostname $VMName -CopyRegionalSettings $CopyRegionalSettings -xml $unattend
$MaxAvailableVersion = (Get-VMHostSupportedVersion).Version | Where-Object {$_.Major -lt 254} | Select-Object -Last 1
Convert-WindowsImage -SourcePath $SourcePath -ISODriveLetter $DriveLetter -Edition $Edition -VHDFormat $Vhdformat -VHDPath $VhdPath -DiskLayout $DiskLayout -UnattendPath $UnattendPath -Parsec:$Parsec -ParsecVDD:$ParsecVDD -DisableHVDD:$DisableHVDD -RDP:$RDP -NumLock:$NumLock -GPUName $GPUName -Team_ID $Team_ID -Key $Key -SizeBytes $SizeBytes | Out-Null
if (Test-Path $vhdPath) {
$Global:VM = New-VM -Name $VMName -MemoryStartupBytes $MemoryAmount -Path $VMPath -VHDPath $VhdPath -Generation 2 -SwitchName $NetworkSwitch -Version $MaxAvailableVersion
$Global:VM | Set-VMMemory -DynamicMemoryEnabled:$DynamicMemoryEnabled
$Global:VM | Set-VM -ProcessorCount $CPUCores
$Global:VM | Set-VM -CheckpointType Disabled
$Global:VM | Set-VM -MemoryMinimum $MemoryAmount
$Global:VM | Set-VM -MemoryMaximum $MemoryMaximum
$Global:VM | Set-VM -LowMemoryMappedIoSpace 3GB
$Global:VM | Set-VM -HighMemoryMappedIoSpace 32GB
$Global:VM | Set-VM -GuestControlledCacheTypes:$true
$Global:VM | Set-VM -AutomaticStopAction ShutDown
$CPUManufacturer = Get-CimInstance -ClassName Win32_Processor | Foreach-Object Manufacturer
$BuildVer = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
if (($BuildVer.CurrentBuild -lt 22000) -and ($CPUManufacturer -eq "AuthenticAMD")) {
} else {
$Global:VM | Set-VMProcessor -ExposeVirtualizationExtensions $true
}
Set-VMHost -ComputerName $ENV:Computername -EnableEnhancedSessionMode $false
$Global:VM | Set-VMVideo -HorizontalResolution 1920 -VerticalResolution 1080
$Global:VM | Set-VMKeyProtector -NewLocalKeyProtector
$Global:VM | Enable-VMTPM
$Global:VM | Add-VMDvdDrive -Path $SourcePath
$Global:VHD = $Global:VM | Get-VMHardDiskDrive
Pass-VMGPUPartitionAdapter
Write-W2VInfo "Starting and connecting to VM"
if ($Global:ServerOS -eq $true) {
Set-ServerOSGroupPolicies
}
vmconnect localhost $VMName
} else {
SmartExit -ExitReason "Failed to create VHDX, stopping script"
}
}
#========================================================================
#========================================================================
function Setup-RemoteDesktop {
param(
[Parameter(Mandatory = $true)][bool]$Parsec,
[bool]$ParsecVDD,
[bool]$DisableHVDD,
[Parameter(Mandatory = $true)][bool]$RDP,
[bool]$NumLock,
[Parameter(Mandatory = $true)][string]$DriveLetter,
[string]$Team_ID,
[string]$Key
)
if (($Parsec -eq $false) -and ($RDP -eq $false) -and ($NumLock -eq $false)) {
return $null
}
New-Item -Path $DriveLetter\Windows\system32\GroupPolicy\User\Scripts\Logon -ItemType directory -Force | Out-Null
New-Item -Path $DriveLetter\Windows\system32\GroupPolicy\User\Scripts\Logoff -ItemType directory -Force | Out-Null
New-Item -Path $DriveLetter\Windows\system32\GroupPolicy\Machine\Scripts\Startup -ItemType directory -Force | Out-Null
New-Item -Path $DriveLetter\Windows\system32\GroupPolicy\Machine\Scripts\Shutdown -ItemType directory -Force | Out-Null
New-Item -Path $DriveLetter\ProgramData\Easy-GPU-P -ItemType directory -Force | Out-Null
$path = "$DriveLetter\Windows\system32\GroupPolicy\User\Scripts\psscripts.ini"
"[Logon]" >> $path
"0CmdLine=Install.ps1" >> $path
"0Parameters=$RDP $Parsec $ParsecVDD $DisableHVDD $NumLock $Team_ID $Key" >> $path
if ($NumLock -eq $true) {
$path = "$DriveLetter\Windows\system32\GroupPolicy\Machine\Scripts\psscripts.ini"
"[Startup]" >> $path
"0CmdLine=NumLockEnable.ps1" >> $path
"0Parameters=" >> $path
$path = "$DriveLetter\Windows\system32\GroupPolicy\Machine\Scripts\Startup\NumLockEnable.ps1"
"`$WshShell = New-Object -ComObject WScript.Shell" >> $path
"for (`$i=0; `$i -lt 5; `$i++) {" >> $path
" Start-Sleep -s 0.1" >> $path
" if ([console]::NumberLock -eq `$false) {" >> $path
" `$WshShell.SendKeys(`"{NUMLOCK}`")" >> $path
" } else { break }" >> $path
"}" >> $path
}
$path = "$DriveLetter\Windows\system32\GroupPolicy\gpt.ini"
"[General]" >> $path
"gPCUserExtensionNames=[{42B5FAAE-6536-11D2-AE5A-0000F87571E3}{40B66650-4972-11D1-A7CA-0000F87571E3}]" >> $path
"Version=131074" >> $path
"gPCMachineExtensionNames=[{42B5FAAE-6536-11D2-AE5A-0000F87571E3}{40B6664F-4972-11D1-A7CA-0000F87571E3}]" >> $path
Copy-Item -Path $psscriptroot\VMScripts\Install.ps1 -Destination $DriveLetter\Windows\system32\GroupPolicy\User\Scripts\Logon
if ($Parsec -eq $true) {
Copy-Item -Path $psscriptroot\VMScripts\VDDMonitor.ps1 -Destination $DriveLetter\ProgramData\Easy-GPU-P
Copy-Item -Path $psscriptroot\misc\ParsecPublic.cer -Destination $DriveLetter\ProgramData\Easy-GPU-P
$compressedDataStream = New-Object System.IO.MemoryStream
$compressedDataStream.Write($parsecLnk, 0, $parsecLnk.Length)
$compressedDataStream.Position = 0
$decompressGzipStream = New-Object System.IO.Compression.GZipStream($compressedDataStream, [System.IO.Compression.CompressionMode]::Decompress)
$decompressedStream = New-Object System.IO.MemoryStream
$buffer = New-Object byte[](1024)
while (($read = $decompressGzipStream.Read($buffer, 0, $buffer.Length)) -gt 0) {
$decompressedStream.Write($buffer, 0, $read)
}
$decompressGzipStream.Close()
$decompressedData = $decompressedStream.ToArray()
[io.file]::WriteAllBytes("$DriveLetter\ProgramData\Easy-GPU-P\Parsec.lnk", $decompressedData)
}
}
#========================================================================
#========================================================================
function Convert-WindowsImage {
<#
.NOTES
Copyright (c) Microsoft Corporation. All rights reserved.
Use of this sample source code is subject to the terms of the Microsoft
license agreement under which you licensed this sample source code. If
you did not accept the terms of the license agreement, you are not
authorized to use this sample source code. For the terms of the license,
please see the license agreement between you and Microsoft or, if applicable,
see the LICENSE.RTF on your install media or the root of your tools installation.
THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
.SYNOPSIS
Creates a bootable VHD(X) based on Windows 7 or Windows 8 installation media.
.DESCRIPTION
Creates a bootable VHD(X) based on Windows 7 or Windows 8 installation media.
.PARAMETER SourcePath
The complete path to the WIM or ISO file that will be converted to a Virtual Hard Disk.
The ISO file must be valid Windows installation media to be recognized successfully.
.PARAMETER CacheSource
If the source WIM/ISO was copied locally, we delete it by default.
Pass $true to cache the source image from the temp directory.
.PARAMETER VHDPath
The name and path of the Virtual Hard Disk to create.
Omitting this parameter will create the Virtual Hard Disk is the current directory, (or,
if specified by the -WorkingDirectory parameter, the working directory) and will automatically
name the file in the following format:
<build>.<revision>.<architecture>.<branch>.<timestamp>_<skufamily>_<sku>_<language>.<extension>
i.e.:
9200.0.amd64fre.winmain_win8rtm.120725-1247_client_professional_en-us.vhd(x)
.PARAMETER WorkingDirectory
Specifies the directory where the VHD(X) file should be generated.
If specified along with -VHDPath, the -WorkingDirectory value is ignored.
The default value is the current directory ($pwd).
.PARAMETER TempDirectory
Specifies the directory where the logs and ISO files should be placed.
The default value is the temp directory ($env:Temp).
.PARAMETER SizeBytes
The size of the Virtual Hard Disk to create.
For fixed disks, the VHD(X) file will be allocated all of this space immediately.
For dynamic disks, this will be the maximum size that the VHD(X) can grow to.
The default value is 40GB.
.PARAMETER VHDFormat
Specifies whether to create a VHD or VHDX formatted Virtual Hard Disk.
The default is AUTO, which will create a VHD if using the BIOS disk layout or
VHDX if using UEFI or WindowsToGo layouts.
.PARAMETER DiskLayout
Specifies whether to build the image for BIOS (MBR), UEFI (GPT), or WindowsToGo (MBR).
Generation 1 VMs require BIOS (MBR) images. Generation 2 VMs require UEFI (GPT) images.
Windows To Go images will boot in UEFI or BIOS but are not technically supported (upgrade
doesn't work)
.PARAMETER UnattendPath
The complete path to an unattend.xml file that can be injected into the VHD(X).
.PARAMETER Edition
The name or image index of the image to apply from the WIM.
.PARAMETER Passthru
Specifies that the full path to the VHD(X) that is created should be
returned on the pipeline.
.PARAMETER BCDBoot
By default, the version of BCDBOOT.EXE that is present in \Windows\System32
is used by Convert-WindowsImage. If you need to specify an alternate version,
use this parameter to do so.
.PARAMETER MergeFolder
Specifies additional MergeFolder path to be added to the root of the VHD(X)
.PARAMETER BCDinVHD
Specifies the purpose of the VHD(x). Use NativeBoot to skip cration of BCD store
inside the VHD(x). Use VirtualMachine (or do not specify this option) to ensure
the BCD store is created inside the VHD(x).
.PARAMETER Driver
Full path to driver(s) (.inf files) to inject to the OS inside the VHD(x).
.PARAMETER ExpandOnNativeBoot
Specifies whether to expand the VHD(x) to its maximum suze upon native boot.
The default is True. Set to False to disable expansion.
.PARAMETER RDP
Enable Remote Desktop to connect to the OS inside the VHD(x) upon provisioning.
.PARAMETER Parsec
Install Remote Desktop app Parsec.
.PARAMETER ParsecVDD
Install Remote Desktop app Parsec Virtual Display Driver
.PARAMETER DisableHVDD
Disable Hyper-V Display Driver
.PARAMETER Numlock
Enable / Disable NumLock at logon
.PARAMETER Feature
Enables specified Windows Feature(s). Note that you need to specify the Internal names
understood by DISM and DISM CMDLets (e.g. NetFx3) instead of the "Friendly" names
from Server Manager CMDLets (e.g. NET-Framework-Core).
.PARAMETER Package
Injects specified Windows Package(s). Accepts path to either a directory or individual
CAB or MSU file.
.PARAMETER ShowUI
Specifies that the Graphical User Interface should be displayed.
.PARAMETER EnableDebugger
Configures kernel debugging for the VHD(X) being created.
EnableDebugger takes a single argument which specifies the debugging transport to use.
Valid transports are: None, Serial, 1394, USB, Network, Local.
Depending on the type of transport selected, additional configuration parameters will become
available.
Serial: -ComPort - The COM port number to use while communicating with the debugger.
The default value is 1 (indicating COM1).
-BaudRate - The baud rate (in bps) to use while communicating with the debugger.
The default value is 115200, valid values are:
9600, 19200, 38400, 56700, 115200
1394: -Channel - The 1394 channel used to communicate with the debugger.
The default value is 10.
USB: -Target - The target name used for USB debugging (the default value is "debugging").
Network: -IPAddress - The IP address of the debugging host computer.
-Port - The port on which to connect to the debugging host.
The default value is 50000, with a minimum value of 49152.
-Key - The key used to encrypt the connection. Only [0-9] and [a-z] are allowed.
-nodhcp - Prevents the use of DHCP to obtain the target IP address.
-newkey - Specifies that a new encryption key should be generated for the connection.
.PARAMETER DismPath
Full Path to an alternative version of the Dism.exe tool. The default is the current OS version.
.PARAMETER ApplyEA
Specifies that any EAs captured in the WIM should be applied to the VHD.
The default is False.
.EXAMPLE
.\Convert-WindowsImage.ps1 -SourcePath D:\foo\install.wim -Edition Professional -WorkingDirectory D:\foo
This command will create a 40GB dynamically expanding VHD in the D:\foo folder.
The VHD will be based on the Professional edition from D:\foo\install.wim,
and will be named automatically.
.EXAMPLE
.\Convert-WindowsImage.ps1 -SourcePath D:\foo\Win7SP1.iso -Edition Ultimate -VHDPath D:\foo\Win7_Ultimate_SP1.vhd
This command will parse the ISO file D:\foo\Win7SP1.iso and try to locate
\sources\install.wim. If that file is found, it will be used to create a
dynamically-expanding 40GB VHD containing the Ultimate SKU, and will be
named D:\foo\Win7_Ultimate_SP1.vhd
.EXAMPLE
.\Convert-WindowsImage.ps1 -SourcePath D:\foo\install.wim -Edition Professional -EnableDebugger Serial -ComPort 2 -BaudRate 38400
This command will create a VHD from D:\foo\install.wim of the Professional SKU.
Serial debugging will be enabled in the VHD via COM2 at a baud rate of 38400bps.
.OUTPUTS
System.IO.FileInfo
#>
[CmdletBinding(DefaultParameterSetName = "SRC",
HelpURI = "https://github.com/Microsoft/Virtualization-Documentation/tree/master/hyperv-tools/Convert-WindowsImage")]
param(
[Parameter(ParameterSetName = "SRC", Mandatory = $true,ValueFromPipeline = $true)]
[Alias("WIM")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $(Resolve-Path $_) })]
$SourcePath,
[Parameter(ParameterSetName = "SRC")]
[Alias("DriveLetter")]
[string]
[ValidateNotNullOrEmpty()]
[string]$ISODriveLetter,
[Parameter(ParameterSetName = "SRC")]
[Alias("GPU")]
[string]
[ValidateNotNullOrEmpty()]
[string]$GPUName,
[Parameter(ParameterSetName = "SRC")]
[Alias("TeamID")]
[string]
#[ValidateNotNullOrEmpty()]
[string]$Team_ID,
[Parameter(ParameterSetName = "SRC")]
[Alias("Teamkey")]
[string]
#[ValidateNotNullOrEmpty()]
[string]$Key,
[Parameter(ParameterSetName = "SRC")]
[switch]
$CacheSource = $false,
[Parameter(ParameterSetName = "SRC")]
[Alias("SKU")]
[string[]]
[ValidateNotNullOrEmpty()]
$Edition,
[Parameter(ParameterSetName = "SRC")]
[Alias("WorkDir")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $_ })]
$WorkingDirectory = $pwd,
[Parameter(ParameterSetName = "SRC")]
[Alias("TempDir")]
[string]
[ValidateNotNullOrEmpty()]
$TempDirectory = $env:Temp,
[Parameter(ParameterSetName = "SRC")]
[Alias("VHD")]
[string]
[ValidateNotNullOrEmpty()]
$VHDPath,
[Parameter(ParameterSetName = "SRC")]
[Alias("Size")]
[uint64]
[ValidateNotNullOrEmpty()]
[ValidateRange(512MB,64TB)]
$SizeBytes = 25GB,
[Parameter(ParameterSetName = "SRC")]
[Alias("Format")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateSet("VHD","VHDX","AUTO")]
$VHDFormat = "AUTO",
[Parameter(ParameterSetName = "SRC")]
[Alias("MergeFolder")]
[string]
[ValidateNotNullOrEmpty()]
$MergeFolderPath = "",
[Parameter(ParameterSetName = "SRC",Mandatory = $true)]
[Alias("Layout")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateSet("BIOS","UEFI","WindowsToGo")]
$DiskLayout,
[Parameter(ParameterSetName = "SRC")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateSet("NativeBoot","VirtualMachine")]
$BCDinVHD = "VirtualMachine",
[Parameter(ParameterSetName = "SRC")]
[Parameter(ParameterSetName = "UI")]
[string]
$BCDBoot = "bcdboot.exe",
[Parameter(ParameterSetName = "SRC")]
[Parameter(ParameterSetName = "UI")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateSet("None","Serial","1394","USB","Local","Network")]
$EnableDebugger = "None",
[Parameter(ParameterSetName = "SRC")]
[string[]]
[ValidateNotNullOrEmpty()]
$Feature,
[Parameter(ParameterSetName = "SRC")]
[string[]]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $(Resolve-Path $_) })]
$Driver,
[Parameter(ParameterSetName = "SRC")]
[string[]]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $(Resolve-Path $_) })]
$Package,
[Parameter(ParameterSetName = "SRC")]
[switch]
$ExpandOnNativeBoot = $true,
[Parameter(ParameterSetName = "SRC")]
[bool]
$RDP,
[Parameter(ParameterSetName = "SRC")]
[bool]
$Parsec,
[Parameter(ParameterSetName = "SRC")]
[bool]
$ParsecVDD,
[Parameter(ParameterSetName = "SRC")]
[bool]
$DisableHVDD,
[Parameter(ParameterSetName = "SRC")]
[bool]
$NumLock,
[Parameter(ParameterSetName = "SRC")]
[Alias("Unattend")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $(Resolve-Path $_) })]
$UnattendPath,
[Parameter(ParameterSetName = "SRC")]
[Parameter(ParameterSetName = "UI")]
[switch]
$Passthru,
[Parameter(ParameterSetName = "SRC")]
[string]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path $(Resolve-Path $_) })]
$DismPath,
[Parameter(ParameterSetName = "SRC")]
[switch]
$ApplyEA = $false,
[Parameter(ParameterSetName = "UI")]
[switch]
$ShowUI
)
#region Code
# Begin Dynamic Parameters
# Create the parameters for the various types of debugging.
dynamicparam {
#Set-StrictMode -version 3
# Set up the dynamic parameters.
# Dynamic parameters are only available if certain conditions are met, so they'll only show up
# as valid parameters when those conditions apply. Here, the conditions are based on the value of
# the EnableDebugger parameter. Depending on which of a set of values is the specified argument
# for EnableDebugger, different parameters will light up, as outlined below.
$parameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
if (!(Test-Path Variable:Private:EnableDebugger)) {
return $parameterDictionary
}
switch ($EnableDebugger){
"Serial" {
#region ComPort
$ComPortAttr = New-Object System.Management.Automation.ParameterAttribute
$ComPortAttr.ParameterSetName = "__AllParameterSets"
$ComPortAttr.Mandatory = $false
$ComPortValidator = New-Object System.Management.Automation.ValidateRangeAttribute (
1,
10 # Is that a good maximum?
)
$ComPortNotNull = New-Object System.Management.Automation.ValidateNotNullOrEmptyAttribute
$ComPortAttrCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$ComPortAttrCollection.Add($ComPortAttr)
$ComPortAttrCollection.Add($ComPortValidator)
$ComPortAttrCollection.Add($ComPortNotNull)
$ComPort = New-Object System.Management.Automation.RuntimeDefinedParameter (