This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtoolsHCK.ps1
2402 lines (2185 loc) · 108 KB
/
toolsHCK.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
<#
.SYNOPSIS
toolsHCK: Powershell wrapper for HCK\HLK Studio API.
.DESCRIPTION
A script tool set for HCK\HLK automation powered by HCK\HLK API provided with the Microsoft's Windows HCK\HLK Studio.
.NOTES
Author: Bishara AbuHattoum <[email protected]>
License: BSD
#>
# server switch to inform the script is to run as a server
[CmdletBinding()]
param([Switch]$server, [Int]$port = 4000, [Int]$timeout = 60, [Int]$polling = 10)
if ($env:WTTSTDIO -like "*\Hardware Certification Kit\*") {
$Studio = "hck"
if ($env:PROCESSOR_ARCHITECTURE -ne "x86") {
if (-Not $json) {
Write-Warning "HCK script should be run under a 32bit PowerShell"
Write-Host "Redirecting ..."
}
$PowerShell = [System.IO.Path]::Combine($PSHOME.tolower().replace("system32","sysWOW64"), "powershell.exe")
$Params = [String]::Empty
if ($server) {
$Params += "-server -port $port -timeout $timeout -polling $polling"
}
$Invocation = "$PSCommandPath $Params"
Invoke-Expression "Invoke-Command -ScriptBlock { $PowerShell -File $Invocation }"
exit $LASTEXITCODE
}
} else {
$Studio = "hlk"
}
##
$Version = "0.0.3"
$MaxJsonDepth = 6
##
#
# Loadinf HCK\HLK libraries
[System.Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "\microsoft.windows.kits.hardware.filterengine.dll") | Out-Null
[System.Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "\microsoft.windows.kits.hardware.objectmodel.dll") | Out-Null
[System.Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "\microsoft.windows.kits.hardware.objectmodel.dbconnection.dll") | Out-Null
[System.Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "\microsoft.windows.kits.hardware.objectmodel.submission.dll") | Out-Null
[System.Reflection.Assembly]::LoadFrom($env:WTTSTDIO + "\microsoft.windows.kits.hardware.objectmodel.submission.package.dll") | Out-Null
#
# Task
function New-Task($name, $stage, $status, $taskerrormessage, $tasktype, $childtasks) {
$task = New-Object PSObject
$task | Add-Member -type NoteProperty -Name name -Value $name
$task | Add-Member -type NoteProperty -Name stage -Value $stage
$task | Add-Member -type NoteProperty -Name status -Value $status
$task | Add-Member -type NoteProperty -Name taskerrormessage -Value $taskerrormessage
$task | Add-Member -type NoteProperty -Name tasktype -Value $tasktype
$task | Add-Member -type NoteProperty -Name childtasks -Value $childtasks
return $task
}
#
# PackageProgressInfo
function New-PackageProgressInfo($current, $maximum, $message) {
$packageprogressinfo = New-Object PSObject
$packageprogressinfo | Add-Member -type NoteProperty -Name current -Value $current
$packageprogressinfo | Add-Member -type NoteProperty -Name maximum -Value $maximum
$packageprogressinfo | Add-Member -type NoteProperty -Name message -Value $message
return $packageprogressinfo
}
#
# ProjectPackage
function New-ProjectPackage($name, $projectpackagepath) {
$projectpackage = New-Object PSObject
$projectpackage | Add-Member -type NoteProperty -Name name -Value $name
$projectpackage | Add-Member -type NoteProperty -Name projectpackagepath -Value $projectpackagepath
return $projectpackage
}
#
# TestResultLogsZip
function New-TestResultLogsZip($testname, $testid,$status, $logszippath) {
$testresultlogszip = New-Object PSObject
$testresultlogszip | Add-Member -type NoteProperty -Name testname -Value $testname
$testresultlogszip | Add-Member -type NoteProperty -Name testid -Value $testid
$testresultlogszip | Add-Member -type NoteProperty -Name status -Value $status
$testresultlogszip | Add-Member -type NoteProperty -Name logszippath -Value $logszippath
return $testresultlogszip
}
#
# TestResult
function New-TestResult($name, $completiontime, $scheduletime, $starttime, $status, $instanceid, $arefiltersapplied, $target, $tasks) {
$testresult = New-Object PSObject
$testresult | Add-Member -type NoteProperty -Name name -Value $name
$testresult | Add-Member -type NoteProperty -Name completiontime -Value $completiontime
$testresult | Add-Member -type NoteProperty -Name scheduletime -Value $scheduletime
$testresult | Add-Member -type NoteProperty -Name starttime -Value $starttime
$testresult | Add-Member -type NoteProperty -Name status -Value $status
$testresult | Add-Member -type NoteProperty -Name instanceid -Value $instanceid
$testresult | Add-Member -type NoteProperty -Name arefiltersapplied -Value $arefiltersapplied
$testresult | Add-Member -type NoteProperty -Name target -Value $target
$testresult | Add-Member -type NoteProperty -Name tasks -Value $tasks
return $testresult
}
#
# FilterResult
function New-FilterResult($appliedfilterson) {
$filterresult = New-Object PSObject
$filterresult | Add-Member -type NoteProperty -Name appliedfilterson -Value $appliedfilterson
return $filterresult
}
#
# Test
function New-Test($name, $id, $testtype, $estimatedruntime, $requiresspecialconfiguration, $requiressupplementalcontent, $scheduleoptions, $status, $executionstate) {
$test = New-Object PSObject
$test | Add-Member -type NoteProperty -Name name -Value $name
$test | Add-Member -type NoteProperty -Name id -Value $id
$test | Add-Member -type NoteProperty -Name testtype -Value $testtype
$test | Add-Member -type NoteProperty -Name estimatedruntime -Value $estimatedruntime
$test | Add-Member -type NoteProperty -Name requiresspecialconfiguration -Value $requiresspecialconfiguration
$test | Add-Member -type NoteProperty -Name requiressupplementalcontent -Value $requiressupplementalcontent
$test | Add-Member -type NoteProperty -Name scheduleoptions -Value $scheduleoptions
$test | Add-Member -type NoteProperty -Name status -Value $status
$test | Add-Member -type NoteProperty -Name executionstate -Value $executionstate
return $test
}
#
# ProductInstanceTarget
function New-ProductInstanceTarget($name, $key, $machine) {
$productinstancetarget = New-Object PSObject
$productinstancetarget | Add-Member -type NoteProperty -Name name -Value $name
$productinstancetarget | Add-Member -type NoteProperty -Name key -Value $key
$productinstancetarget | Add-Member -type NoteProperty -Name machine -Value $machine
return $productinstancetarget
}
#
# ProductInstance
function New-ProductInstance($name, $osplatform, $targetedpool, $targets) {
$productinstance = New-Object PSObject
$productinstance | Add-Member -type NoteProperty -Name name -Value $name
$productinstance | Add-Member -type NoteProperty -Name osplatform -Value $osplatform
$productinstance | Add-Member -type NoteProperty -Name targetedpool -Value $targetedpool
$productinstance | Add-Member -type NoteProperty -Name targets -Value $targets
return $productinstance
}
#
# Project
function New-Project($name, $creationtime, $modifiedtime, $status, $productinstances) {
$project = New-Object PSObject
$project | Add-Member -type NoteProperty -Name name -Value $name
$project | Add-Member -type NoteProperty -Name creationtime -Value $creationtime
$project | Add-Member -type NoteProperty -Name modifiedtime -Value $modifiedtime
$project | Add-Member -type NoteProperty -Name status -Value $status
$project | Add-Member -type NoteProperty -Name productinstances -Value $productinstances
return $project
}
#
# Target
function New-Target($name, $key, $type) {
$target = New-Object PSObject
$target | Add-Member -type NoteProperty -Name name -Value $name
$target | Add-Member -type NoteProperty -Name key -Value $key
$target | Add-Member -type NoteProperty -Name type -value $type
return $target
}
#
# Machine
function New-Machine($name, $state, $lastheartbeat) {
$machine = New-Object PSObject
$machine | Add-Member -type NoteProperty -Name name -Value $name
$machine | Add-Member -type NoteProperty -Name state -Value $state
$machine | Add-Member -type NoteProperty -Name lastheartbeat -Value $lastheartbeat
return $machine
}
#
# Pool
function New-Pool($name, $machines) {
$pool = New-Object PSObject
$pool | Add-Member -type NoteProperty -Name name -Value $name
$pool | Add-Member -type NoteProperty -Name machines -Value $machines
return $pool
}
#
# ActionResult
function New-ActionResult($content, $exception = $nil) {
$actionresult = New-Object PSObject
if ([String]::IsNullOrEmpty($exception)) {
$actionresult | Add-Member -type NoteProperty -Name result -Value "Success"
if (-Not [String]::IsNullOrEmpty($content)) {
$jsoncontent = (ConvertFrom-Json $content)
if ($jsoncontent -is [System.Object[]]) {
$actionresult | Add-Member -type NoteProperty -Name content -Value $jsoncontent.SyncRoot
} else {
$actionresult | Add-Member -type NoteProperty -Name content -Value $jsoncontent
}
}
} else {
$actionresult | Add-Member -type NoteProperty -Name result -Value "Failure"
if ([String]::IsNullOrEmpty($exception.InnerException)) {
$actionresult | Add-Member -type NoteProperty -Name message -Value $exception.Message
} else {
$actionresult | Add-Member -type NoteProperty -Name message -Value $exception.InnerException.Message
}
}
return $actionresult
}
# ------------------------------------------------------------ #
# Functions, one for each action the script is able to perform #
# ------------------------------------------------------------ #
# ListPools
function listpools {
[CmdletBinding()]
param([Switch]$help)
function Usage {
Write-Output "listpools:"
Write-Output ""
Write-Output "A script that lists the pools info."
Write-Output "and last heart beat."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "listpools [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if (-Not $json) {
foreach ($Pool in $RootPool.GetChildPools()) {
Write-Output "============================================="
Write-Output "Pool name : $($Pool.Name)"
Write-Output ""
$Machines = $Pool.GetMachines()
if ($Machines.Count -lt 1) {
Write-Output " The pool is empty!"
} else {
Write-Output " Machines :"
foreach ($Machine in $Machines) {
Write-Output " Name : $($Machine.Name)"
Write-Output " State : $($Machine.Status)"
Write-Output " Last heart beat : $($Machine.LastHeartBeat)"
Write-Output ""
}
}
Write-Output "============================================="
}
} else {
$poolslist = New-Object System.Collections.ArrayList
foreach ($Pool in $RootPool.GetChildPools()) {
$machineslist = New-Object System.Collections.ArrayList
$Machines = $Pool.GetMachines()
foreach ($Machine in $Machines) {
$machineslist.Add((New-Machine $Machine.Name $Machine.Status.ToString() $Machine.LastHeartBeat.ToString())) | Out-Null
}
$poolslist.Add((New-Pool $Pool.Name $machineslist)) | Out-Null
}
ConvertTo-Json @($poolslist) -Depth 3 -Compress
}
}
#
# CreatePool
function createpool {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$pool)
function Usage {
Write-Output "createpool:"
Write-Output ""
Write-Output "A script that creates a pool."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "createpool <poolname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {
throw "Please provide a pool's name."
}
}
if (-Not $json) { Write-Output "Creating pool $pool in Root pool." }
$RootPool.CreateChildPool($pool) | Out-Null
}
#
# DeletePool
function deletepool {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$pool)
function Usage {
Write-Output "deletepool:"
Write-Output ""
Write-Output "A script that deletes a pool."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "deletepool <poolname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {
throw "Please provide a pool's name."
}
}
if (-Not ($WntdPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $pool })) { throw "Provided pool's name is not valid, aborting..."}
if (-Not $json) { Write-Output "Deleting pool $pool in Root pool." }
$RootPool.DeleteChildPool($WntdPool)
}
#
# MoveMachine
function movemachine {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$machine, [Parameter(Position=2)][String]$from, [Parameter(Position=3)][String]$to)
function Usage {
Write-Output "movemachine:"
Write-Output ""
Write-Output "A script that moves a machine from one pool to another."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "movemachine <machine> <frompool> <topool> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " machine = The name of the machine as registered with the HCK\HLK controller."
Write-Output ""
Write-Output " frompool = The name of the source pool."
Write-Output ""
Write-Output " topool = The name of the destination pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($machine)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a machine's name."
Usage; return
} else {
throw "Please provide a machine's name."
}
}
if ([String]::IsNullOrEmpty($from)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a source pool's name."
Usage; return
} else {
throw "Please provide a source pool's name."
}
}
if ([String]::IsNullOrEmpty($to)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a destination pool's name."
Usage; return
} else {
throw "Please provide a destination pool's name."
}
}
if (-Not ($WntdFromPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $from })) { throw "Provided source pool's name is not valid, aborting..." }
if (-Not ($WntdToPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $to })) { throw "Provided destination pool's name is not valid, aborting..." }
if (-Not ($WntdMachine = $WntdFromPool.GetMachines() | Where-Object { $_.Name -eq $machine })) { throw "Provided machines's name is not valid, aborting..." }
if (-Not $json) { Write-Output "Moving machine $($WntdMachine.Name) from $($WntdFromPool.Name) to $($WntdToPool.Name) pool." }
$WntdFromPool.MoveMachineTo($WntdMachine, $WntdToPool)
}
#
# SetMachineState
function setmachinestate {
[CmdletBinding()]
param([Switch]$help, [Int]$timeout = -1, [Parameter(Position=1)][String]$machine, [Parameter(Position=2)][String]$pool, [Parameter(Position=3)][String]$state)
function Usage {
Write-Output "setmachinestate:"
Write-Output ""
Write-Output "A script that sets the state of a machine to Ready or NotReady."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "setmachinestate <machine> <poolname> <state> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " machine = The name of the machine as registered with the HCK\HLK controller."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output " state = The state, Ready or NotReady."
Write-Output ""
Write-Output " timeout = The operation's timeout in seconds, disabled by default."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($machine)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a machine's name."
Usage; return
} else {
throw "Please provide a machine's name."
}
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {
throw "Please provide a pool's name."
}
}
if ([String]::IsNullOrEmpty($state)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a state."
Usage; return
} else {
throw "Please provide a state."
}
}
if (-Not ($WntdPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $pool })) { throw "Provided pool's name is not valid, aborting..." }
if (-Not ($WntdMachine = $WntdPool.GetMachines() | Where-Object { $_.Name -eq $machine })) { throw "Provided machines's name is not valid, aborting..." }
if (-Not ($timeout -eq -1)) { $timeout = $timeout * 1000 }
if (-Not $json) { Write-Output "Setting machine $($WntdMachine.Name) to $state state..." }
switch ($state) {
"Ready" {
if (-Not $WntdMachine.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::Ready, $timeout)) { throw "Unable to change machine state, timed out." }
}
"NotReady" {
if (-Not $WntdMachine.SetMachineStatus([Microsoft.Windows.Kits.Hardware.ObjectModel.MachineStatus]::NotReady, $timeout)) { throw "Unable to change machine state, timed out." }
}
default {
throw "Provided desired machines's sate is not valid, aborting..."
}
}
}
#
# DeleteMachine
function deletemachine {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$machine, [Parameter(Position=2)][String]$pool)
function Usage {
Write-Output "deletemachine:"
Write-Output ""
Write-Output "A script that deletes a machine."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "deletemachine <machine> <poolname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " machine = The name of the machine as registered with the HCK\HLK controller."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($machine)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a machine's name."
Usage; return
} else {
throw "Please provide a machine's name."
}
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {
throw "Please provide a pool's name."
}
}
if (-Not ($WntdPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $pool })) { throw "Provided pool's name is not valid, aborting..." }
if (-Not $json) { Write-Output "Deleting machine $machine..." }
$WntdPool.DeleteMachine($machine)
}
#
# ListMachineTargets
function listmachinetargets {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$machine, [Parameter(Position=2)][String]$pool)
function Usage {
Write-Output "listmachinetargets:"
Write-Output ""
Write-Output "A script that lists the target devices of a machine that are available to be tested."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "listmachientargets <testmachine> <poolname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " testmachine = The name of the machine as registered with the HCK\HLK controller."
Write-Output " NOTE: test machine should be in a READY state."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($machine)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a machine's name."
Usage; return
} else {
throw "Please provide a machine's name."
}
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {
throw "Please provide a pool's name."
}
}
if (-Not ($WntdPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $pool })) { throw "Did not find pool $pool in Root pool, aborting..." }
if (-Not ($WntdMachine = $WntdPool.GetMachines()| Where-Object { $_.Name -eq $machine })) { throw "The test machine was not found, aborting..." }
if (-Not $json) {
Write-Output ""
Write-Output "The tests targets on $($WntdMachine.Name) are:"
Write-Output ""
foreach ($TestTarget in $WntdMachine.GetTestTargets()) {
Write-Output "============================================="
Write-Output "Target name : $($TestTarget.Name)"
Write-Output ""
Write-Output " Key : $($TestTarget.Key)"
Write-Output " Type : $($TestTarget.TargetType)"
Write-Output ""
Write-Output "============================================="
}
} else {
$targetslist = New-Object System.Collections.ArrayList
foreach ($TestTarget in $WntdMachine.GetTestTargets()) {
$targetslist.Add((New-Target $TestTarget.Name $TestTarget.Key $TestTarget.TargetType)) | Out-Null
}
ConvertTo-Json @($targetslist) -Compress
}
}
#
# ListProjects
function listprojects {
[CmdletBinding()]
param([Switch]$help)
function Usage {
Write-Output "listprojects:"
Write-Output ""
Write-Output "A script that lists the projects info."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "listprojects [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if (-Not $json) {
foreach ($ProjectName in $Manager.GetProjectNames()) {
$Project = $Manager.GetProject($ProjectName)
Write-Output "============================================="
Write-Output "Project name : $($Project.Name)"
Write-Output ""
Write-Output " Creation time : $($Project.CreationTime)"
Write-Output " Modified time : $($Project.ModifiedTime)"
Write-Output " Status : $($Project.Info.Status)"
Write-Output ""
$ProductInstances = $Project.GetProductInstances()
if ($ProductInstances.Count -lt 1) {
Write-Output " No product instances!"
} else {
Write-Output " Product instances :"
foreach ($Pi in $ProductInstances) {
Write-Output " Name : $($Pi.Name)"
Write-Output " OSPlatform : $($Pi.OSPlatform.Name)"
Write-Output " Targeted pool : $($Pi.MachinePool.Name)"
Write-Output " Targets :"
foreach ($Target in $Pi.GetTargets()) {
Write-Output " Name : $($Target.Name)"
Write-Output " Key : $($Target.Key)"
Write-Output " Type : $($Target.TargetType)"
Write-Output " Machine : $($Target.Machine.Name)"
Write-Output ""
}
}
}
Write-Output "============================================="
}
} else {
$projectslist = New-Object System.Collections.ArrayList
foreach ($ProjectName in $Manager.GetProjectNames()) {
$Project = $Manager.GetProject($ProjectName)
$ProductInstances = $Project.GetProductInstances()
$productinstanceslist = New-Object System.Collections.ArrayList
foreach ($Pi in $ProductInstances) {
$targetslist = New-Object System.Collections.ArrayList
foreach ($Target in $Pi.GetTargets()) {
$targetslist.Add((New-ProductInstanceTarget $Target.Name $Target.Key $Target.Machine.Name)) | Out-Null
}
$productinstanceslist.Add((New-ProductInstance $Pi.Name $Pi.OSPlatform.Name $Pi.MachinePool.Name $targetslist)) | Out-Null
}
$projectslist.Add((New-Project $Project.Name $Project.CreationTime.ToString() $Project.ModifiedTime.ToString() $Project.Info.Status.ToString() $productinstanceslist)) | Out-Null
}
ConvertTo-Json @($projectslist) -Depth 5 -Compress
}
}
#
# CreateProject
function createproject {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$project)
function Usage {
Write-Output "createproject:"
Write-Output ""
Write-Output "A script that creates a project."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "createproject <projectname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " projectname = The name of the project."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($project)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a project's name."
Usage; return
} else {
throw "Please provide a project's name."
}
}
if ($Manager.GetProjectNames().Contains($project)) {
throw "A project with the name $($project) already exists, aborting..."
} else {
if (-Not $json) { Write-Output "Creating a new project named $($project)." }
$WntdProject = $Manager.CreateProject($project)
}
}
#
# DeleteProject
function deleteproject {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$project)
function Usage {
Write-Output "deleteproject:"
Write-Output ""
Write-Output "A script that deletes a project."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "deleteproject <projectname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " projectname = The name of the project."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($project)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a project's name."
Usage; return
} else {
throw "Please provide a project's name."
}
}
if (-Not $json) { Write-Output "Deleting project $project..." }
$Manager.DeleteProject($project)
}
#
# CreateProjectTarget
function createprojecttarget {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$target, [Parameter(Position=2)][String]$project, [Parameter(Position=3)][String]$machine, [Parameter(Position=4)][String]$pool)
function Usage {
Write-Output "createprojecttarget:"
Write-Output ""
Write-Output "A script that creates a project's target."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "createprojecttarget <targetkey> <projectname> <testmachine> <poolname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " tagetkey = The key of the target, use listmachinetargets to get it."
Write-Output ""
Write-Output " projectname = The name of the project."
Write-Output ""
Write-Output " testmachine = The name of the machine as registered with the HCK\HLK controller."
Write-Output " NOTE: test machine should be in a READY state."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($target)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a target's key."
Usage; return
} else {
throw "Please provide a target's key."
}
}
if ([String]::IsNullOrEmpty($project)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a project's name."
Usage; return
} else {
throw "Please provide a project's name."
}
}
if ([String]::IsNullOrEmpty($machine)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a machine's name."
Usage; return
} else {
throw "Please provide a machine's name."
}
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {
throw "Please provide a pool's name."
}
}
if (-Not ($WntdPool = $RootPool.GetChildPools() | Where-Object { $_.Name -eq $pool })) { throw "Did not find pool $pool in Root pool, aborting..." }
if (-Not ($WntdMachine = $WntdPool.GetMachines()| Where-Object { $_.Name -eq $machine })) { throw "The test machine was not found, aborting..." }
if (-Not ($WntdTarget = $WntdMachine.GetTestTargets() | Where-Object { $_.Key -eq $target })) { throw "A target that matches the target's key given was not found in the specified machine, aborting..." }
if (-Not ($Manager.GetProjectNames().Contains($project))) { throw "No project with the given name was found, aborting..." } else { $WntdProject = $Manager.GetProject($project) }
$CreatedPI = $false
if (-Not ($WntdPI = $WntdProject.GetProductInstances() | Where-Object { $_.OSPlatform -eq $WntdMachine.OSPlatform })) {
if (-Not $WntdProject.CanCreateProductInstance($WntdMachine.OSPlatform.Description, $WntdPool, $WntdMachine.OSPlatform)) {
throw "Can't create the project's product instance, it may be due to the project having another product instance that matches the wanted machine's pool or platform."
} else {
$WntdPI = $WntdProject.CreateProductInstance($WntdMachine.OSPlatform.Description, $WntdPool, $WntdMachine.OSPlatform)
$CreatedPI = $true
}
}
try {
$WntdPITargets = $WntdPI.GetTargets()
if (($WntdTarget.TargetType -eq "System") -and ($WntdPITargets | Where-Object { $_.TargetType -ne "System" })) { throw "The project already has non-system targets, can't mix system and non-system targets, aborting..." }
if (($WntdTarget.TargetType -ne "System") -and ($WntdPITargets | Where-Object { $_.TargetType -eq "System" })) { throw "The project already has system targets, can't mix system and non-system targets, aborting..." }
else {
$WntdtoTarget = New-Object System.Collections.ArrayList
if ($WntdTarget.TargetType -eq "TargetCollection") {
foreach ($toTarget in $WntdPI.FindTargetFromContainer($WntdTarget.ContainerId)) {
if ($toTarget.Machine.Equals($WntdMachine)){
$WntdtoTarget.Add($toTarget) | Out-Null
}
}
} else {
$WntdtoTarget.Add($WntdTarget) | Out-Null
}
if ($WntdtoTarget.Count -lt 1) { throw "No targets to create were found, aborting..." }
foreach ($toTarget in $WntdtoTarget) {
if ($WntdPITargets | Where-Object { ($_.Key -eq $toTarget.Key) -and $_.Machine.Equals($toTarget.Machine) }) { continue }
switch ($toTarget.TargetType) {
"Filter" { [String[]]$HardwareIds = $toTarget.Key }
"System" { [String[]]$HardwareIds = "[SYSTEM]" }
default { [String[]]$HardwareIds = $toTarget.HardwareId }
}
if (-Not ($WntdDeviceFamily = $Manager.GetDeviceFamilies() | Where-Object { $_.Name -eq $HardwareIds[0] })) {
$WntdDeviceFamily = $Manager.CreateDeviceFamily($HardwareIds[0], $HardwareIds)
}
if ($WntdPITargets | Where-Object { ($_.Key -eq $toTarget.Key) }) {
$WntdTargetFamily = ($WntdPITargets | Where-Object { ($_.Key -eq $toTarget.Key) })[0].TargetFamily
} else {
$WntdTargetFamily = $WntdPI.CreateTargetFamily($WntdDeviceFamily)
}
if (-Not $json) { Write-Output "Creating a new project's target from $($toTarget.Name)." }
$WntdTargetFamily.CreateTarget($toTarget) | Out-Null
}
}
} catch {
if ($CreatedPI) { $WntdProject.DeleteProductInstance($WntdMachine.OSPlatform.Description) }
throw
}
}
#
# DeleteProjectTarget
function deleteprojecttarget {
[CmdletBinding()]
param([Switch]$help, [Parameter(Position=1)][String]$target, [Parameter(Position=2)][String]$project, [Parameter(Position=3)][String]$machine, [Parameter(Position=4)][String]$pool)
function Usage {
Write-Output "deleteprojecttarget:"
Write-Output ""
Write-Output "A script that deletes a project's target."
Write-Output "These tasks are done by using the HCK\HLK API provided with the Windows HCK\HLK Studio."
Write-Output ""
Write-Output "Usage:"
Write-Output ""
Write-Output "deleteprojecttarget <targetkey> <projectname> <testmachine> <poolname> [-help]"
Write-Output ""
Write-Output "Any parameter in [] is optional."
Write-Output ""
Write-Output " help = Shows this message."
Write-Output ""
Write-Output " tagetkey = The key of the target, use listmachinetargets to get it."
Write-Output ""
Write-Output " projectname = The name of the project."
Write-Output ""
Write-Output " testmachine = The name of the machine as registered with the HCK\HLK controller."
Write-Output " NOTE: test machine should be in a READY state."
Write-Output ""
Write-Output " poolname = The name of the pool."
Write-Output ""
Write-Output "NOTE: Windows HCK\HLK Studio should be installed on the machine running the script!"
}
if ($help) {
if (-Not $json) { Usage; return } else { throw "Help requested, ignoring..." }
}
if ([String]::IsNullOrEmpty($target)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a target's key."
Usage; return
} else {
throw "Please provide a target's key."
}
}
if ([String]::IsNullOrEmpty($project)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a project's name."
Usage; return
} else {
throw "Please provide a project's name."
}
}
if ([String]::IsNullOrEmpty($machine)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a machine's name."
Usage; return
} else {
throw "Please provide a machine's name."
}
}
if ([String]::IsNullOrEmpty($pool)) {
if (-Not $json) {
Write-Output "WARNING: Please provide a pool's name."
Usage; return
} else {