-
Notifications
You must be signed in to change notification settings - Fork 247
/
CreateScript.ps1
1572 lines (1441 loc) · 68.2 KB
/
CreateScript.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
Param(
[switch] $skipContainerHelperCheck,
[string] $predefinedpw = 'P@ssw0rd'
)
# create script for running docker
$ErrorActionPreference = "stop"
function Select-Value {
Param(
[Parameter(Mandatory=$false)]
[string] $title,
[Parameter(Mandatory=$false)]
[string] $description,
[Parameter(Mandatory=$true)]
$options,
[Parameter(Mandatory=$false)]
[string] $default = "",
[Parameter(Mandatory=$true)]
[string] $question,
[switch] $doNotClearHost = ($host.name -ne "ConsoleHost"),
[switch] $writeAnswer = ($host.name -ne "ConsoleHost"),
[switch] $previousStep
)
if (!$doNotClearHost) {
Clear-Host
}
if ($title) {
Write-Host -ForegroundColor Yellow $title
Write-Host
}
if ($description) {
Write-Host $description
Write-Host
}
$offset = 0
$defaultChr = -1
$keys = @()
$values = @()
$options.GetEnumerator() | ForEach-Object {
Write-Host -ForegroundColor Yellow "$([char]($offset+97)) " -NoNewline
$keys += @($_.Key)
$values += @($_.Value)
if ($_.Key -eq $default) {
Write-Host -ForegroundColor Yellow $_.Value
$defaultAnswer = $offset
}
else {
Write-Host $_.Value
}
$offset++
}
Write-Host
if ($script:thisStep -lt 100) {
if (($default) -and !$script:acceptDefaults) {
Write-Host -ForegroundColor Yellow "!" -NoNewline
Write-Host " accept default answers for the remaining questions"
}
if ($previousStep) {
Write-Host -ForegroundColor Yellow "x" -NoNewline
Write-Host " start over"
Write-Host -ForegroundColor Yellow "z" -NoNewline
Write-Host " go back"
}
if (($default) -or ($previousStep)) {
Write-Host
}
}
$answer = -1
do {
Write-Host "$question " -NoNewline
if ($defaultAnswer -ge 0) {
Write-Host "(default $([char]($defaultAnswer + 97))) " -NoNewline
}
if ($script:acceptDefaults -and $defaultAnswer -ge 0) {
$selection = ""
}
else {
$selection = (Read-Host).ToLowerInvariant()
}
if ($selection -eq "!" -and ($default)) {
$selection = ""
$script:acceptDefaults = $true
Write-Host $defaultAnswer
}
if ($previousStep) {
if ($selection -eq "x") {
if ($writeAnswer) {
Write-Host
Write-Host -ForegroundColor Green "Start over selected"
Write-Host
}
$script:acceptDefaults = $false
$script:wizardStep = 0
$script:prevSteps = New-Object System.Collections.Stack
$script:prevSteps.Push(1)
return "Back"
}
if ($selection -eq "z") {
if ($writeAnswer) {
Write-Host
Write-Host -ForegroundColor Green "Back selected"
Write-Host
}
$script:acceptDefaults = $false
$script:wizardStep = $script:prevSteps.Pop()
return "Back"
}
}
if ($selection -eq "") {
if ($defaultAnswer -ge 0) {
$answer = $defaultAnswer
}
else {
Write-Host -ForegroundColor Red "No default value exists. " -NoNewline
}
}
else {
if (($selection.Length -ne 1) -or (([int][char]($selection)) -lt 97 -or ([int][char]($selection)) -ge (97+$offset))) {
Write-Host -ForegroundColor Red "Illegal answer. " -NoNewline
}
else {
$answer = ([int][char]($selection))-97
}
}
if ($answer -eq -1) {
if ($offset -eq 2) {
Write-Host -ForegroundColor Red "Please answer one letter, a or b"
}
else {
Write-Host -ForegroundColor Red "Please answer one letter, from a to $([char]($offset+97-1))"
}
}
} while ($answer -eq -1)
if ($writeAnswer) {
Write-Host
Write-Host -ForegroundColor Green "$($values[$answer]) selected"
Write-Host
}
$keys[$answer]
}
function Enter-Value {
Param(
[Parameter(Mandatory=$false)]
[string] $title,
[Parameter(Mandatory=$false)]
[string] $description,
[Parameter(Mandatory=$false)]
$options,
[Parameter(Mandatory=$false)]
[string] $default = "",
[Parameter(Mandatory=$true)]
[string] $question,
[switch] $doNotClearHost = ($host.name -ne "ConsoleHost"),
[switch] $writeAnswer = ($host.name -ne "ConsoleHost"),
[switch] $doNotConvertToLower,
[switch] $previousStep
)
if (!$doNotClearHost) {
Clear-Host
}
if ($title) {
Write-Host -ForegroundColor Yellow $title
Write-Host
}
if ($description) {
Write-Host $description
Write-Host
}
if ($script:thisStep -lt 100) {
if (($default) -and !$script:acceptDefaults) {
Write-Host -ForegroundColor Yellow "!" -NoNewline
Write-Host " accept default answers for the remaining questions"
}
if ($previousStep) {
Write-Host "Enter " -NoNewline
Write-Host -ForegroundColor Yellow "x" -NoNewline
Write-Host " to start over"
Write-Host "Enter " -NoNewline
Write-Host -ForegroundColor Yellow "z" -NoNewline
Write-Host " to go back"
}
if (($default) -or ($previousStep)) {
Write-Host
}
}
$answer = ""
do {
Write-Host "$question " -NoNewline
if ($options) {
Write-Host "($([string]::Join(', ', $options))) " -NoNewline
}
if ($default) {
Write-Host "(default $default) " -NoNewline
}
if ($script:acceptDefaults -and ($default)) {
$selection = ""
Write-Host $default
}
elseif ($doNotConvertToLower) {
$selection = Read-Host
}
else {
$selection = (Read-Host).ToLowerInvariant()
}
if ($selection -eq "!" -and ($default)) {
$selection = ""
$script:acceptDefaults = $true
}
if ($selection -eq "") {
if ($default) {
$answer = $default
}
else {
Write-Host -ForegroundColor Red "No default value exists. "
}
}
elseif ($selection -eq "x" -and $previousStep) {
if ($writeAnswer) {
Write-Host
Write-Host -ForegroundColor Green "Exit selected"
Write-Host
}
$script:acceptDefaults = $false
$script:wizardStep = 0
$script:prevSteps = New-Object System.Collections.Stack
$script:prevSteps.Push(1)
return "back"
}
elseif ($selection -eq "z" -and $previousStep) {
if ($writeAnswer) {
Write-Host
Write-Host -ForegroundColor Green "Back selected"
Write-Host
}
$script:acceptDefaults = $false
$script:wizardStep = $script:prevSteps.Pop()
return "back"
}
else {
if ($options) {
$answer = $options | Where-Object { $_ -eq $selection }
if (-not ($answer)) {
$answer = $options | Where-Object { $_ -like "$selection*" }
if (-not ($answer)) {
Write-Host -ForegroundColor Red "Illegal answer. Please answer one of the options."
}
elseif ($answer -is [Array]) {
Write-Host -ForegroundColor Red "Multiple options match the answer. Please answer one of the options that matched the previous selection."
$options = $answer
$answer = $null
}
}
}
else {
$answer = $selection
}
}
} while (-not ($answer))
if ($writeAnswer) {
Write-Host
Write-Host -ForegroundColor Green "$answer selected"
Write-Host
}
$answer
}
function randomchar([string]$str)
{
$rnd = Get-Random -Maximum $str.length
[string]$str[$rnd]
}
function Get-RandomPassword {
$cons = 'bcdfghjklmnpqrstvwxz'
$voc = 'aeiouy'
$numbers = '0123456789'
((randomchar $cons).ToUpper() + `
(randomchar $voc) + `
(randomchar $cons) + `
(randomchar $voc) + `
(randomchar $numbers) + `
(randomchar $numbers) + `
(randomchar $numbers) + `
(randomchar $numbers))
}
Clear-Host
$pshost = Get-Host
$pswindow = $pshost.UI.RawUI
$minWidth = 150
if (($pswindow.BufferSize) -and ($pswindow.WindowSize) -and ($pswindow.WindowSize.Width -lt $minWidth)) {
$buffersize = $pswindow.BufferSize
$buffersize.width = $minWidth
try {
$pswindow.buffersize = $buffersize
}
catch {}
$newsize = $pswindow.windowsize
$newsize.width = $minWidth
try {
$pswindow.windowsize = $newsize
}
catch {}
}
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdministrator = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
$randompw = Get-RandomPassword
$os = (Get-CimInstance Win32_OperatingSystem)
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
throw "Unknown Host Operating System"
}
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")
$ErrorActionPreference = "STOP"
$script:wizardStep = 0
$script:acceptDefaults = $false
$Step = @{
"BcContainerHelper" = 0
"AcceptEula" = 1
"Hosting" = 2
"Authentication" = 3
"ContainerName" = 4
"Version" = 5
"Version2" = 7
"Country" = 8
"TestToolkit" = 9
"PerformanceToolkit" = 10
"PremiumPlan" = 11
"CreateTestUsers" = 12
"IncludeAL" = 20
"ExportAlSource" = 21
"IncludeCSIDE" = 22
"ExportCAlSource" = 23
"Vsix" = 24
"License" = 30
"Database" = 31
"Multitenant" = 32
"DNS" = 35
"SSL" = 36
"Isolation" = 40
"Memory" = 41
"SaveImage" = 50
"Special" = 60
"Final" = 100
}
$script:prevSteps = New-Object System.Collections.Stack
$script:prevSteps.Push(1)
while ($script:wizardStep -le 100) {
$script:thisStep = $script:wizardStep
$script:wizardStep++
switch ($script:thisStep) {
$Step.BcContainerHelper {
Write-Host -ForegroundColor Yellow @'
____ _____ _ _ _ _ _
| _ \ / ____| | | (_) | | | | | |
| |_) | ___| | ___ _ __ | |_ __ _ _ _ __ ___ _ __| |__| | ___| |_ __ ___ _ __
| _ < / __| | / _ \| '_ \| __/ _` | | '_ \ / _ \ '__| __ |/ _ \ | '_ \ / _ \ '__|
| |_) | (__| |____ (_) | | | | |_ (_| | | | | | __/ | | | | | __/ | |_) | __/ |
|____/ \___|\_____\___/|_| |_|\__\__,_|_|_| |_|\___|_| |_| |_|\___|_| .__/ \___|_|
| |
|_|
'@
if (!$skipContainerHelperCheck) {
$module = Get-InstalledModule -Name "BcContainerHelper" -ErrorAction SilentlyContinue
if (!($module)) {
$module = Get-Module -Name "BcContainerHelper" -ErrorAction SilentlyContinue
}
if (!($module)) {
Write-Host -ForegroundColor Red "This script has a dependency on the PowerShell module BcContainerHelper."
Write-Host -ForegroundColor Red "See more here: https://www.powershellgallery.com/packages/bccontainerhelper"
Write-Host -ForegroundColor Red "Use 'Install-Module BcContainerHelper -force' to install in PowerShell"
return
}
elseif ($module.Version -eq "0.0") {
Write-Host -ForegroundColor Green "You are running BcContainerHelper developer version"
Write-Host
}
else {
$myVersion = $module.Version.ToString()
$prerelease = $myVersion.Contains("-preview")
if ($prerelease) {
$latestVersion = (Find-Module -Name bccontainerhelper -AllowPrerelease).Version
$previewStr = "Prerelease version "
}
else {
$latestVersion = (Find-Module -Name bccontainerhelper).Version
$previewStr = ""
}
if ($latestVersion -eq $myVersion) {
Write-Host -ForegroundColor Green "You are running BcContainerHelper $previewStr$myVersion (which is the latest version)"
}
else {
Write-Host -ForegroundColor Yellow "You are running BcContainerHelper $previewStr$myVersion. A newer version ($latestVersion) exists, please consider updating."
}
Write-Host
}
}
}
$Step.AcceptEula {
$acceptEula = Enter-Value `
-title @'
_ ______ _
/\ | | | ____| | |
/ \ ___ ___ ___ _ __ | |_ | |__ _ _| | __ _
/ /\ \ / __/ __/ _ \ '_ \| __| | __|| | | | |/ _` |
/ ____ \ (__ (__ __/ |_) | |_ | |____ |_| | | (_| |
/_/ \_\___\___\___| .__/ \__| |______\__,_|_|\__,_|
| |
|_|
'@ `
-Description "This script will generate a script, which can be used to run Business Central in Docker on your computer.`nYou will be asked a number of questions and the generated script should create a container, which matches your needs.`n`nIn order to run Business Central in Docker, you will need to accept the eula.`nThe supplemental license terms for running Business Central and NAV on Docker can be found here: https://go.microsoft.com/fwlink/?linkid=861843" `
-options @("Y","N") `
-question "Please enter Y if you accept the eula"
if ($acceptEula -ne "Y") {
Write-Host -ForegroundColor Red "Eula not accepted, aborting..."
return
}
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
$Step.Hosting {
$hosting = Select-Value `
-title @'
_ _ _____ _ _ __ ____ __
| | | | / ____| | | (_) /\ \ \ / / \/ |
| | ___ ___ __ _| | | | ___ _ __ | |_ __ _ _ _ __ ___ _ __ ___ _ __ / \ _____ _ _ __ ___ \ \ / /| \ / |
| | / _ \ / __/ _` | | | | / _ \| '_ \| __/ _` | | '_ \ / _ \ '__| / _ \| '__| / /\ \ |_ / | | | '__/ _ \ \ \/ / | |\/| |
| |____ (_) | (__ (_| | | | |____ (_) | | | | |_ (_| | | | | | __/ | | (_) | | / ____ \ / /| |_| | | | __/ \ / | | | |
|______\___/ \___\__,_|_| \_____\___/|_| |_|\__\__,_|_|_| |_|\___|_| \___/|_| /_/ \_\___|\__,_|_| \___| \/ |_| |_|
'@ `
-description "Specify where you want to host your Business Central container?`n`nSelecting Local will create a script that needs to run on a computer, which have Docker installed.`nSelecting Azure VM shows a Url with which you can create a VM. This requires an Azure Subscription." `
-options ([ordered]@{"Local" = "Local docker container"; "AzureVM" = "Docker container in an Azure VM"}) `
-question "Hosting" `
-default "Local" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
$Step.Authentication {
if ($hosting -eq "Local") {
$auth = Select-Value `
-title @'
_ _ _ _ _ _
/\ | | | | | | (_) | | (_)
/ \ _ _| |_| |__ ___ _ __ | |_ _ ___ __ _| |_ _ ___ _ __
/ /\ \| | | | __| '_ \ / _ \ '_ \| __| |/ __/ _` | __| |/ _ \| '_ \
/ ____ \ |_| | |_| | | | __/ | | | |_| | (__ (_| | |_| | (_) | | | |
/_/ \_\__,_|\__|_| |_|\___|_| |_|\__|_|\___\__,_|\__|_|\___/|_| |_|
'@ `
-description "Select desired authentication mechanism.`nSelecting predefined credentials means that the script will use hardcoded credentials.`n`nNote: When using Windows authentication, you need to use your Windows Credentials from the host computer and if the computer is domain joined, you will need to be connected to the domain while running the container. You cannot use containers with Windows authentication when offline." `
-options ([ordered]@{"UserPassword" = "Username/Password authentication"; "Credential" = "Username/Password authentication (admin with predefined password - $predefinedpw)"; "Random" = "Username/Password authentication (admin with random password - $randompw)"; "Windows" = "Windows authentication"}) `
-question "Authentication" `
-default "Credential" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
else {
$auth = "UserPassword"
}
}
$Step.ContainerName {
if ($hosting -eq "Local") {
$containerName = Enter-Value `
-title @'
_____ _ _ _ _
/ ____| | | (_) | \ | |
| | ___ _ __ | |_ __ _ _ _ __ ___ _ __ | \| | __ _ _ __ ___ ___
| | / _ \| '_ \| __/ _` | | '_ \ / _ \ '__| | . ` |/ _` | '_ ` _ \ / _ \
| |____ (_) | | | | |_ (_| | | | | | __/ | | |\ | (_| | | | | | | __/
\_____\___/|_| |_|\__\__,_|_|_| |_|\___|_| |_| \_|\__,_|_| |_| |_|\___|
'@ `
-description "Enter the name of the container.`nContainer names are case sensitive and must start with a letter.`n`nNote: We recommend short lower case names as container names." `
-question "Container name" `
-default "bcserver" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
else {
$containerName = $bcContainerHelperConfig.defaultContainerName
}
}
$Step.Version {
if ($hosting -eq "local") { $back = 4 } else { $back = 2 }
$predef = Select-Value `
-title @'
__ __ _
\ \ / / (_)
\ \ / /__ _ __ ___ _ ___ _ __
\ \/ / _ \ '__/ __| |/ _ \| '_ \
\ / __/ | \__ \ | (_) | | | |
\/ \___|_| |___/_|\___/|_| |_|
'@ `
-description "What version of Business Central do you need?`nIf you are developing a Per Tenant Extension for a Business Central Saas tenant, you need a Business Central Sandbox environment" `
-options ([ordered]@{
"LatestSandbox" = "Latest Business Central Sandbox"
"LatestOnPrem" = "Latest Business Central OnPrem"
"Next Major" = "Insider Business Central Sandbox for Next Major release (you automatically accept the insider EULA (https://go.microsoft.com/fwlink/?linkid=2245051) by using this option)"
"Next Minor" = "Insider Business Central Sandbox for Next Minor release (you automatically accept the insider EULA (https://go.microsoft.com/fwlink/?linkid=2245051) by using this option)"
"SpecificSandbox" = "Specific Business Central Sandbox build (requires version number)"
"SpecificOnPrem" = "Specific Business Central OnPrem build (requires version number)"
"NAV2018" = "Specific NAV 2018 version"
"NAV2017" = "Specific NAV 2017 version"
"NAV2016" = "Specific NAV 2016 version"
}) `
-question "Version" `
-default "LatestSandbox" `
-writeAnswer `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
$Step.Version2 {
$fullVersionNo = $false
$select = "Latest"
$storageAccount = "bcartifacts"
$nav = ""
if ($predef -like "latest*") {
$type = $predef.Substring(6)
$version = ''
}
elseif ($predef -like "Next*") {
$type = "Sandbox"
$version = ''
$storageAccount = "bcinsider"
if ($predef -eq "Next Minor") {
$select = "SecondToLastMajor"
}
}
elseif ($predef -like "NAV*") {
$nav = $predef.Substring(3)
$type = "Onprem"
$ok = $false
do {
$cus = Get-NavArtifactUrl -nav $nav -country 'w1' -select All
$cu = Enter-Value `
-description "NAV $nav has $($cus.Count-1) released cumulative updates." `
-question "Enter CU number (0 is rtm or leave blank for latest)" `
-default "latest" `
-doNotClearHost `
-writeAnswer `
-previousStep
if ($cu -eq "back") {
$ok = $true
}
else {
$cuno = $cus.Count-1
if ($cu -eq "latest" -or ([int]::TryParse($cu, [ref]$cuno) -and ($cuno -ge 0) -and ($cuno -lt $($cus.Count)))) {
$ok = $true
$version = $cus[$cuno].split('/')[4]
}
}
} while (!$ok)
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
elseif ($predef -like "specific*") {
$type = $predef.Substring(8)
$ok = $false
do {
$version = Enter-Value `
-description "Specify version number.`nIf you specify a full version number (like 15.4.41023.41345), you will get the closest version.`nIf multiple versions matches the entered value, you will be asked to select" `
-question "Enter version number (format major[.minor[.build[.release]]])" `
-doNotClearHost `
-writeAnswer `
-previousStep
if ($version -eq "back") {
$ok = $true
}
else {
if ($version.indexOf('.') -eq -1) {
$verno = 0
$ok = [int32]::TryParse($version, [ref]$verno)
if (!$ok) {
Write-Host -ForegroundColor Red "Illegal version number"
}
}
else {
$verno = [Version]"0.0.0.0"
$ok = [Version]::TryParse($version, [ref]$verno)
if (!$ok) {
Write-Host -ForegroundColor Red "Illegal version number"
}
$fullVersionNo = $verno.Revision -ne -1
}
if ($ok) {
if ($fullVersionNo) {
$select = "Closest"
$artifactUrl = Get-BCArtifactUrl -type $type -version $version -country 'w1' -select 'Closest'
if ($artifactUrl) {
$foundVersion = $artifactUrl.split('/')[4]
if ($foundVersion -ne $version) {
Write-Host -ForegroundColor Yellow "The specific version doesn't exist, closest version is $foundVersion"
}
}
}
else {
$versions = @()
Get-BCArtifactUrl -type $type -version $version -country 'w1' -select All | ForEach-Object {
$versions += $_.Split('/')[4]
}
if ($versions.Count -eq 0) {
Write-Host -ForegroundColor Red "Unable to find a version matching the specified version"
$ok = $false
}
elseif ($versions.Count -gt 1) {
$version = Enter-Value `
-options $versions `
-question "Select specific version" `
-doNotClearHost `
-writeAnswer `
-previousStep
if ($version -eq "back") {
$ok = $true
}
else {
$fullVersionNo = $true
}
}
}
}
}
} while (!$ok)
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$Step.Country {
Write-Host "Analyzing artifacts"
$versionno = $version
if ($versionno -eq "") {
$searchCountry = "us"
if ($type -eq 'sandbox') { $searchCountry = "at" }
$aurl = Get-BcArtifactUrl -storageAccount $storageAccount -type $type -country $searchCountry -select $select -accept_insiderEula
$versionno = $aurl.split('/')[4]
}
$majorVersion = [int]($versionno.Split('.')[0])
$countries = @()
Get-BCArtifactUrl -storageAccount $storageAccount -type $type -version $versionno -select All -accept_insiderEula | ForEach-Object {
$countries += $_.SubString($_.LastIndexOf('/')+1).Split('?')[0]
}
$description = ""
if ($version -ne "") {
$description += "Version $version selected`n`n"
}
else {
$description += "Version $versionno identified`n`n"
}
if ($type -eq "Sandbox") {
$default = "us"
$description += "Please select which country version you want to use.`n`nNote: base is the onprem w1 demodata running in sandbox mode."
}
else {
$default = "w1"
$description += "Please select which country version you want to use.`n`nNote: NA contains US, CA and MX."
}
$country = Enter-Value `
-title @'
_____ _
/ ____| | |
| | ___ _ _ _ __ | |_ _ __ _ _
| | / _ \| | | | '_ \| __| '__| | | |
| |____ (_) | |_| | | | | |_| | | |_| |
\_____\___/ \__,_|_| |_|\__|_| \__, |
__/ |
|___/
'@ `
-description $description `
-options $countries `
-default $default `
-question "Country" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
$Step.TestToolkit {
if ($majorVersion -ge 18) {
$licenseNote = "Full Test Toolkit requires a license in order to be used"
}
else {
$licenseNote = "Test Libraries requires a license in order to be used"
}
$testtoolkit = Select-Value `
-title @'
_______ _ _______ _ _ _ _
|__ __| | | |__ __| | | | (_) |
| | ___ ___| |_ | | ___ ___ | | | ___| |_
| |/ _ \ __| __| | |/ _ \ / _ \| | |/ / | __|
| | __\__ \ |_ | | (_) | (_) | | <| | |_
|_|\___|___/\__| |_|\___/ \___/|_|_|\_\_|\__|
'@ `
-description "Do you need the test toolkit to be installed?`nThe Test Toolkit is needed in order to develop and run tests in the container.`n`nNote: $licenseNote" `
-options ([ordered]@{"All" = "Full Test Toolkit (Test Framework, Test Libraries and Microsoft tests)"; "Libraries" = "Test Framework and Test Libraries"; "Framework" = "Test Framework"; "No" = "No Test Toolkit needed"}) `
-question "Test Toolkit" `
-default "No" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
$Step.PerformanceToolkit {
$performanceToolkit = "N"
if ($majorVersion -ge 17 -and $testtoolkit -ne "No") {
$performancetoolkit = Enter-Value `
-title @'
_____ __ _______ _ _ _ _
| __ \ / _| |__ __| | | | (_) |
| |__) |__ _ __| |_ ___ _ __ _ __ ___ __ _ _ __ ___ ___ | | ___ ___ | | | ___| |_
| ___/ _ \ '__| _/ _ \| '__| '_ ` _ \ / _` | '_ \ / __/ _ \ | |/ _ \ / _ \| | |/ / | __|
| | | __/ | | || (_) | | | | | | | | (_| | | | | (__ __/ | | (_) | (_) | | <| | |_
|_| \___|_| |_| \___/|_| |_| |_| |_|\__,_|_| |_|\___\___| |_|\___/ \___/|_|_|\_\_|\__|
'@ `
-description "The Performance Toolkit ships with Business Central 17.0.`n`nDo you need the performance toolkit to be installed?`nThe Performance Toolkit is needed in order to develop and run performance tests in the container." `
-options @("Y","N") `
-question "Please enter Y if you want to install the performance toolkit" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$Step.PremiumPlan {
$assignPremiumPlan = "N"
if ($type -eq "Sandbox") {
if ($hosting -eq "local") { $back = 8 } else { $back = 7 }
$assignPremiumPlan = Enter-Value `
-title @'
_____ _ _____ _
| __ \ (_) | __ \| |
| |__) | __ ___ _ __ ___ _ _ _ _ __ ___ | |__) | | __ _ _ __
| ___/ '__/ _ \ '_ ` _ \| | | | | '_ ` _ \ | ___/| |/ _` | '_ \
| | | | | __/ | | | | | | |_| | | | | | | | | | | (_| | | | |
|_| |_| \___|_| |_| |_|_|\__,_|_| |_| |_| |_| |_|\__,_|_| |_|
'@ `
-Description "When running sandbox, you can select to assign premium plan to the users." `
-options @("Y","N") `
-question "Please enter Y if you want to assign premium plan" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$step.IncludeAL {
$includeAL = "N"
if ($hosting -eq 'local' -and $majorVersion -gt 14) {
$includeAL = Enter-Value `
-title @'
_ ____ _____ _ _
/\ | | | _ \ /\ | __ \ | | | |
/ \ | | | |_) | __ _ ___ ___ / \ _ __ _ __ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_
/ /\ \ | | | _ < / _` / __|/ _ \ / /\ \ | '_ \| '_ \ | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __|
/ ____ \| |____ | |_) | (_| \__ \ __/ / ____ \| |_) | |_) | | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_
/_/ \_\______| |____/ \__,_|___/\___| /_/ \_\ .__/| .__/ |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__|
| | | | | |
|_| |_| |_|
'@ `
-Description "If you are going to perform base app development (modify and publish the base application), you will need to use an option called -includeAL.`n`nThis option is not needed if you are going to write extensions only." `
-options @("Y","N") `
-question "Please enter Y if you need to do base app development" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$step.ExportAlSource {
$exportAlSource = "N"
if ($includeAL -eq "Y") {
$exportALSource = Enter-Value `
-title @'
______ _ _ ____
| ____| | | /\ | | | _ \ /\
| |__ __ ___ __ ___ _ __| |_ / \ | | | |_) | __ _ ___ ___ / \ _ __ _ __
| __| \ \/ / '_ \ / _ \| '__| __| / /\ \ | | | _ < / _` / __|/ _ \ / /\ \ | '_ \| '_ \
| |____ > <| |_) | (_) | | | |_ / ____ \| |____ | |_) | (_| \__ \ __/ / ____ \| |_) | |_) |
|______/_/\_\ .__/ \___/|_| \__| /_/ \_\______| |____/ \__,_|___/\___| /_/ \_\ .__/| .__/
| | | | | |
|_| |_| |_|
'@ `
-Description "When specifying -includeAL, the default behavior is to export the AL source code as a project for you to modify, compile and publish.`nIf you already have a source code repository this is obviously not needed and can be avoided by specifying an option called -doNotExportObjectsToText.`n`nDo you want to export the Base App as an AL source code project?" `
-options @("Y","N") `
-question "Please enter Y if you want to export the base app AL source code" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$step.IncludeCSIDE {
$includeCSIDE = "N"
if ($hosting -eq 'local' -and $majorVersion -le 14) {
if ($majorVersion -lt 14) {
$product = "NAV"
}
else {
$product = "a version of Business Central"
}
$includeCSIDE = Enter-Value `
-title @'
_____ __ _ _____ _ _
/ ____| / /\ | | | __ \ | | | |
| | / / \ | | | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_
| | / / /\ \ | | | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __|
| |____ / / ____ \| |____ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_
\_____/_/_/ \_\______| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__|
| |
|_|
'@ `
-Description "You are running $product, which includes the legacy Windows Client and legacy C/AL development.`nIf you are going to use the Windows Client or use C/AL development, you will need to use an option called -includeCSIDE." `
-options @("Y","N") `
-question "Please enter Y if you need CSIDE or Windows Client" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$step.ExportCAlSource {
$exportCAlSource = "N"
if ($includeCSIDE -eq "Y") {
$exportCAlSource = Enter-Value `
-title @'
______ _ _____ __ _ ____
| ____| | | / ____| / /\ | | | _ \ /\
| |__ __ ___ __ ___ _ __| |_ | | / / \ | | | |_) | __ _ ___ ___ / \ _ __ _ __
| __| \ \/ / '_ \ / _ \| '__| __| | | / / /\ \ | | | _ < / _` / __|/ _ \ / /\ \ | '_ \| '_ \
| |____ > <| |_) | (_) | | | |_ | |____ / / ____ \| |____ | |_) | (_| \__ \ __/ / ____ \| |_) | |_) |
|______/_/\_\ .__/ \___/|_| \__| \_____/_/_/ \_\______| |____/ \__,_|___/\___| /_/ \_\ .__/| .__/
| | | | | |
|_| |_| |_|
'@ `
-Description "When specifying -includeCSIDE, the default behavior is to export the C/AL source code as text files.`nIf you already have a source code repository this is obviously not needed and can be avoided by specifying an option called -doNotExportObjectsToText.`n`nDo you want to export the C/AL base app as text files?" `
-options @("Y","N") `
-question "Please enter Y if you want to export the C/AL base app as text files" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$Step.Vsix {
$vsix = "N"
if ($hosting -eq 'local' -and $majorVersion -gt 14) {
$vsix = Enter-Value `
-title @'
_ _ ______ _ _
/\ | | | | | ____| | | (_)
/ \ | | | | __ _ _ __ __ _ _ _ __ _ __ _ ___ | |__ __ __ |_ ___ _ __ ___ _ ___ _ __
/ /\ \ | | | | / _` | '_ \ / _` | | | |/ _` |/ _` |/ _ \ | __| \ \/ / __/ _ \ '_ \/ __| |/ _ \| '_ \
/ ____ \| |____ | |____ (_| | | | | (_| | |_| | (_| | (_| | __/ | |____ > <| |_ __/ | | \__ \ | (_) | | | |
/_/ \_\______| |______\__,_|_| |_|\__, |\__,_|\__,_|\__, |\___| |______/_/\_\\__\___|_| |_|___/_|\___/|_| |_|
__/ | __/ |
|___/ |___/
'@ `
-description "The AL language extension used in the container is normally the vsix file that comes with the version of Business Central selected.`n`nYou can select to use the latest shipped AL Language extension from the marketplace by specifying -vsixFile <url>." `
-options @("Y","N") `
-question "Please enter Y if you want to use the latest AL Language extension from the marketplace" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$Step.CreateTestUsers {
$createTestUsers = "N"
if ($type -eq "Sandbox") {
$createTestUsers = Enter-Value `
-title @'
_____ _ _______ _ _ _
/ ____| | | |__ __| | | | | | |
| | _ __ ___ __ _| |_ ___ | | ___ ___| |_ | | | |___ ___ _ __ ___
| | | '__/ _ \/ _` | __/ _ \ | |/ _ \ __| __| | | | / __|/ _ \ '__/ __|
| |____| | | __/ (_| | |_ __/ | | __\__ \ |_ | |__| \__ \ __/ | \__ \
\_____|_| \___|\__,_|\__\___| |_|\___|___/\__| \____/|___/\___|_| |___/
'@ `
-Description "When running sandbox, you can select to add test users with special entitlements.`nThe users created are: ExternalAccountant, Premium, Essential, InternalAdmin, TeamMember and DelegatedAdmin.`n`nNote: This requires a license file to be specified." `
-options @("Y","N") `
-question "Please enter Y if you want to create test users" `
-default "N" `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
$script:prevSteps.Push($script:thisStep)
}
}
}
$Step.License {
if ($majorVersion -ge 18) {
$licenserequired = ($testtoolkit -eq "All" -or $createTestUsers -eq "Y" -or $exportCAlSource -eq "Y" -or $exportAlSource -eq "Y")
}
else {
$licenserequired = ($testtoolkit -eq "All" -or $testtoolkit -eq "Libraries" -or $performanceToolkit -eq "Y" -or $createTestUsers -eq "Y" -or $exportCAlSource -eq "Y" -or $exportAlSource -eq "Y")
}
if ($licenserequired) {
$description = "Please specify a license file url.`nDue to other selections, you need to specify a license file."
$default = ""
}
else {
$description = "Please specify a license file url.`nIf you do not specify a license file, you will use the default Cronus Demo License."
$default = "blank"
}
if ($hosting -eq "Local") {
$description += "`n`nThis can be a local file or a secure direct download url (see https://freddysblog.com/2017/02/26/create-a-secure-url-to-a-file/)"
}
else {
$description += "`n`nThis needs to be a secure direct download url (see https://freddysblog.com/2017/02/26/create-a-secure-url-to-a-file/)"
}
$licenseFile = Enter-Value `
-title @'
_ _
| | (_)
| | _ ___ ___ _ __ ___ ___
| | | |/ __/ _ \ '_ \/ __|/ _ \