-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublic.ps1
1209 lines (972 loc) · 85.4 KB
/
Public.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
if (Get-Module -ListAvailable -Name Microsoft.PowerShell.ConsoleGuiTools) {
Write-Host "Console Gui Is installed"
}
else{
Write-Host "Console Gui Is Not installed - Installing" -ForegroundColor Red
Install-Module Microsoft.PowerShell.ConsoleGuiTools
}
if (Get-Module -ListAvailable -Name Az) {
Write-Host "Az Module Is Installed"
}
else{
Write-Host "Az Modules are Is Not installed - Installing" -ForegroundColor Red
Install-Module -Name Az -Repository PSGallery -Force
}
#"Create / refresh assessments and download them for all machines",
#"Generate Tagging Sheet",
#"Generate Health State Infomation",
#"Populate Scope Groups",
#"Populate Production/Non Prodction Groups",
#"Create / refresh assessments and download them for Scope machines",
#"Create / refresh assessments and download them for Production/Non Production machines",
#"Create Assessments from Group"
#"Download Assessments from Group"
# force use of latest PS version, currently hardcoded
#Requires -Version 7.2.2
Add-Type -AssemblyName PresentationFramework
#Login Style - Change Line to login Directly
$Login_via_ADO = $true
$starttime = $(Get-Date -Format "yyyy-MM-ddHH_mm_ss")
$logname = "AzureMigrate_Downlaoder"+$starttime
#change directory to current script execution directory
if ((Get-Host).Name -eq 'Visual Studio Code Host') {
Write-Host "Running on Visual Studio Code !" -f Red
$folder_path = Read-Host "Provide script path"
$path_to_Customers_folder = Read-Host "Provide path to Customers folder"
$path_to_Customers_folder = $path_to_Customers_folder + '\'
}
elseif ((Get-Host).Name -eq 'ConsoleHost' -and ($PSVersionTable).Platform -ceq "Unix") {
Write-Host "Running on Cloud Shell!" -f Green
$folder_path = Read-Host "Provide Path to Script"
$path_to_Customers_folder = new-item $folder_path\Customers -force
$path_to_Customers_folder = $path_to_Customers_folder + '\'
}
else {
Write-Host "Running on Windows Terminal" -f Green
$folder_path = Split-Path $MyInvocation.MyCommand.Path
$path_to_Customers_folder = $path_to_AzureMigrateDownloader_dir + 'Customers\'
}
Set-Location $folder_path
Import-module .\Module\AzMigrate.psm1 -Force -DisableNameChecking -Scope Global
start-Transcript -Path .\$logname.txt
#newline
$nl = [Environment]::NewLine
$dts_stamp = $(Get-Date -Format "yyyy-MM-dd_HH_mm_ss")
#Login via ADO
if ($Login_via_ADO -eq $true) {
Write-host "Loging in Via ADO" -ForegroundColor Green
Set-location $folder_path
$customers_available = Get-AM-Customers
$customer_selected = $customers_available | Select-Object -Property Customer | Sort-Object Customer | Out-ConsoleGridView -Title "Customer" -OutputMode Single
if ($customer_selected -eq $null) { exit }
$customer = $customers_available | Where-Object {$_.Customer -eq $customer_selected.Customer}
$global:customerName = $customer.Customer
$global:containername = Generate-Container-Name -name $customername
$AADID = $customer.'AAD tenant ID'
Set-Location $path_to_Customers_folder
Create-CustomerArea -CustomerName $containername
Set-Location $path_to_Customers_folder\$containername
Write-Host "Creating Assessment Folders" -ForegroundColor Green
Create-Assessment-Folders -dts_stamp $dts_stamp
#$root = Get-Location
#Login
Write-Host "You will now be prompted for Login with your account that has access to the Customer Tennant (USE YOUR V- ACCOUNT!)" -ForegroundColor Cyan
Connect-AzAccount -Tenant $AADID | out-null
$Subscriptions_availaible = Get-AzSubscription -TenantId $AADID
$Subscriptions_selected = $Subscriptions_availaible | select-object name,state,id| Out-ConsoleGridView -Title "Pick the Azure Subscription to run the assessments against" -OutputMode Single
if ($Subscriptions_selected -eq $null) { exit }
$subscrption = $Subscriptions_availaible | where-object {$_.'Name' -eq $Subscriptions_selected.name}
Set-AzContext -Tenant $AADID -Subscription $subscrption.Id| out-null
Write-Host "You are now sucsessfully Logged into the $($customerName) Tennant" -ForegroundColor Green
# Retrieve a bearer token for use when interacting with the underlying REST API:
$token = Get-AzCachedAccessToken
$projects_available = Get-AzureMigrateProject -Token $token -TenantId $AADID
$project_selected = $projects_available | Select-Object -Property "Azure Migrate project display name","RG" | Out-ConsoleGridView -Title "Pick the Azure Migrate project to run the assessments against" -OutputMode Single
if ($project_selected -eq $null) { exit }
$project = $projects_available | Where-Object {$_.'Azure Migrate project display name' -eq $project_selected.'Azure Migrate project display name' -and $_.SubscriptionID -eq $Subscriptions_selected.Id}
$global:SubscriptionID = $project.SubscriptionID
$global:rg = $project.RG
$global:project_name = $project.'Azure Migrate project internal name'
$global:project_friendly_name = $project.'Azure Migrate project display name'
$masterSite = Get-AzureMigrateMasterSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg
if ($mastersite.count -eq 1) {
$mastersite_selected = $mastersite[0]
}
elseif ($mastersite.count -gt 1) {
$all_mastersites = $mastersite | select-object name,@{N = "Project Name"; E = { $_.tags.'Migrate Project' } }| Out-ConsoleGridView -Title "Pick the Azure Migrate mastersite to run the assessments against" -OutputMode Single
$mastersite_selected = $all_mastersites | Where-Object {$_.name -eq $all_mastersites.name}
}
#GET SITE INFOMATION
Write-Host "Storing Site infomation" -ForegroundColor Yellow
$HypervSite = Get-AzureMigrateHyperSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg
if ($HypervSite.count -eq 1) {
$HypervSite_selected = $HypervSite
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -HyperVSiteName $HypervSite_selected.name -ResourceGroup $rg
#$health = Get-AzureMigrateHyperVHealthSiteSummary -Token $token -SubscriptionID $subscrption -ResourceGroup $rg -SiteName $HypervSite_selected.name
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$heartbeat = $HypervSite_selected.Properties.agentDetails.lastHeartBeatUtc
}
elseif ($HypervSite.count -gt 1) {
$all_HypervSite = $HypervSite |Select-Object @{N = "Site Name"; E = { $_.name } },@{N = "Appliance Name"; E = { $_.properties.appliancename } }, @{N = "Project Name"; E = { $_.properties.discoverySolutionId } }| Out-ConsoleGridView -Title "Pick the Azure Migrate VMware to run the assessments against" -OutputMode Single
$HypervSite_selected = $all_HypervSite | Where-Object {$_.name -eq $all_HypervSite.name}
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -HyperVSiteName $HypervSite_selected.name -ResourceGroup $rg
#$health = Get-AzureMigrateHyperVHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -SiteName $HypervSite_selected.'Site Name'
$HypervSite_selected = Get-AzureMigrateVMWareSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $HypervSite_selected.'Site Name'
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$heartbeat = $HypervSite_selected.Properties.agentDetails.lastHeartBeatUtc
#$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
#$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
$VMwareSite = Get-AzureMigrateVMWareSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg
if ($VMwareSite.count -eq 1) {
$VMwareSite_selected = $VMwareSite
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.name -ResourceGroup $rg
$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -SiteName $vmwaresite_selected.name
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
elseif ($VMwareSite.count -gt 1) {
$all_VMwareSites = $VMwareSite |Select-Object @{N = "Site Name"; E = { $_.name } },@{N = "Appliance Name"; E = { $_.properties.appliancename } }, @{N = "Project Name"; E = { $_.properties.discoverySolutionId } }| Out-ConsoleGridView -Title "Pick the Azure Migrate VMware to run the assessments against" -OutputMode Single
$vmwaresite_selected = $all_VMwareSites | Where-Object {$_.name -eq $all_VMwareSites.name}
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.'Site Name' -ResourceGroup $rg
$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $vmwaresite_selected.'Site Name'
$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
$PhysicalSite = Get-AzureMigratePhysicalSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -ProjectName $project_name
if ($PhysicalSite.count -eq 1) {
$PhysicalSite_selected = $PhysicalSite
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.name -ResourceGroup $rg
#$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -SiteName $vmwaresite_selected.name
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
#$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
}
elseif ($PhysicalSite.count -gt 1) {
$all_PhysicalSite = $PhysicalSite |Select-Object @{N = "Site Name"; E = { $_.name } },@{N = "Appliance Name"; E = { $_.properties.appliancename } }, @{N = "Project Name"; E = { $_.properties.discoverySolutionId } }| Out-ConsoleGridView -Title "Pick the Azure Migrate VMware to run the assessments against" -OutputMode Single
$PhysicalSite_selected = $all_PhysicalSite | Where-Object {$_.name -eq $all_PhysicalSite.name}
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.'Site Name' -ResourceGroup $rg
#$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $vmwaresite_selected.'Site Name'
#$vmwaresite_selected = Get-AzureMigrateVMWareSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $vmwaresite_selected.'Site Name'
#$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
}
$ImportSite = Get-AzureMigrateImportSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -ProjectName $project_name
#Get Machine Stats
$discoveredmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
$discoveredSQLmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -SQL
$discoveredAVSmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -AVS
$discoveredCSVmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -Import
if ($discoveredmachines.count -ge 1000) {
Write-host "More then 1000 VM Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeVM = "Weekly"
}
elseif ($discoveredmachines.count -lt 1000) {
$timerangeVM = "Monthly"
}
if ($discoveredCSVmachines.count -ge 1000) {
Write-host "More then 1000 CSV Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeCSV = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeCSV = "Monthly"
}
if ($discoveredSQLmachines.count -ge 1000) {
Write-host "More then 1000 SQL Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeSQL = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeSQL = "Monthly"
}
}
#Loging in Non ADO
elseif ($login_via_ADO -eq $false) {
Write-host "Loging in Via AZ Connect" -ForegroundColor Green
$folder_path = Split-Path $MyInvocation.MyCommand.Path
$path_to_Customers_folder = Read-Host "Provide path to Customers folder"
$path_to_Customers_folder = $path_to_Customers_folder + '\'
Set-location $folder_path
$customer = Read-Host "Customer Name"
$global:customerName = $customer
$global:containername = Generate-Container-Name -name $customername
$AADID = Read-Host "AAD tenant ID"
Set-Location $path_to_Customers_folder
Create-CustomerArea -CustomerName $containername
Set-Location $path_to_Customers_folder\$containername
Write-Host "Creating Assessment Folders" -ForegroundColor Green
Create-Assessment-Folders -dts_stamp $dts_stamp
#$root = Get-Location
#Login
Write-Host "You will now be prompted for Login with your account that has access to the Customer Tennant (USE YOUR V- ACCOUNT!)" -ForegroundColor Cyan
Connect-AzAccount -Tenant $AADID | out-null
$Subscriptions_availaible = Get-AzSubscription -TenantId $AADID
$Subscriptions_selected = $Subscriptions_availaible | select-object name,state,id| Out-ConsoleGridView -Title "Pick the Azure Subscription to run the assessments against" -OutputMode Single
if ($Subscriptions_selected -eq $null) { exit }
$subscrption = $Subscriptions_availaible | where-object {$_.'Name' -eq $Subscriptions_selected.name}
Set-AzContext -Tenant $AADID -Subscription $subscrption.Id| out-null
Write-Host "You are now sucsessfully Logged into the $($customerName) Tennant" -ForegroundColor Green
# Retrieve a bearer token for use when interacting with the underlying REST API:
$token = Get-AzCachedAccessToken
$projects_available = Get-AzureMigrateProject -Token $token -TenantId $AADID
$project_selected = $projects_available | Select-Object -Property "Azure Migrate project display name","RG" | Out-ConsoleGridView -Title "Pick the Azure Migrate project to run the assessments against" -OutputMode Single
if ($project_selected -eq $null) { exit }
$project = $projects_available | Where-Object {$_.'Azure Migrate project display name' -eq $project_selected.'Azure Migrate project display name' -and $_.SubscriptionID -eq $Subscriptions_selected.Id}
$global:SubscriptionID = $project.SubscriptionID
$global:rg = $project.RG
$global:project_name = $project.'Azure Migrate project internal name'
$global:project_friendly_name = $project.'Azure Migrate project display name'
$masterSite = Get-AzureMigrateMasterSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg
if ($mastersite.count -eq 1) {
$mastersite_selected = $mastersite[0]
}
elseif ($mastersite.count -gt 1) {
$all_mastersites = $mastersite | select-object name,@{N = "Project Name"; E = { $_.tags.'Migrate Project' } }| Out-ConsoleGridView -Title "Pick the Azure Migrate mastersite to run the assessments against" -OutputMode Single
$mastersite_selected = $all_mastersites | Where-Object {$_.name -eq $all_mastersites.name}
}
#GET SITE INFOMATION
Write-Host "Storing Site infomation" -ForegroundColor Yellow
$HypervSite = Get-AzureMigrateHyperSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg
if ($HypervSite.count -eq 1) {
$HypervSite_selected = $HypervSite
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -HyperVSiteName $HypervSite_selected.name -ResourceGroup $rg
#$health = Get-AzureMigrateHyperVHealthSiteSummary -Token $token -SubscriptionID $subscrption -ResourceGroup $rg -SiteName $HypervSite_selected.name
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$heartbeat = $HypervSite_selected.Properties.agentDetails.lastHeartBeatUtc
}
elseif ($HypervSite.count -gt 1) {
$all_HypervSite = $HypervSite |Select-Object @{N = "Site Name"; E = { $_.name } },@{N = "Appliance Name"; E = { $_.properties.appliancename } }, @{N = "Project Name"; E = { $_.properties.discoverySolutionId } }| Out-ConsoleGridView -Title "Pick the Azure Migrate VMware to run the assessments against" -OutputMode Single
$HypervSite_selected = $all_HypervSite | Where-Object {$_.name -eq $all_HypervSite.name}
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -HyperVSiteName $HypervSite_selected.name -ResourceGroup $rg
#$health = Get-AzureMigrateHyperVHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -SiteName $HypervSite_selected.'Site Name'
$HypervSite_selected = Get-AzureMigrateVMWareSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $HypervSite_selected.'Site Name'
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$heartbeat = $HypervSite_selected.Properties.agentDetails.lastHeartBeatUtc
#$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
#$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
$VMwareSite = Get-AzureMigrateVMWareSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg
if ($VMwareSite.count -eq 1) {
$VMwareSite_selected = $VMwareSite
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.name -ResourceGroup $rg
$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -SiteName $vmwaresite_selected.name
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
elseif ($VMwareSite.count -gt 1) {
$all_VMwareSites = $VMwareSite |Select-Object @{N = "Site Name"; E = { $_.name } },@{N = "Appliance Name"; E = { $_.properties.appliancename } }, @{N = "Project Name"; E = { $_.properties.discoverySolutionId } }| Out-ConsoleGridView -Title "Pick the Azure Migrate VMware to run the assessments against" -OutputMode Single
$vmwaresite_selected = $all_VMwareSites | Where-Object {$_.name -eq $all_VMwareSites.name}
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.'Site Name' -ResourceGroup $rg
$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $vmwaresite_selected.'Site Name'
$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
$PhysicalSite = Get-AzureMigratePhysicalSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -ProjectName $project_name
if ($PhysicalSite.count -eq 1) {
$PhysicalSite_selected = $PhysicalSite
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.name -ResourceGroup $rg
#$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -SiteName $vmwaresite_selected.name
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
#$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
}
elseif ($PhysicalSite.count -gt 1) {
$all_PhysicalSite = $PhysicalSite |Select-Object @{N = "Site Name"; E = { $_.name } },@{N = "Appliance Name"; E = { $_.properties.appliancename } }, @{N = "Project Name"; E = { $_.properties.discoverySolutionId } }| Out-ConsoleGridView -Title "Pick the Azure Migrate VMware to run the assessments against" -OutputMode Single
$PhysicalSite_selected = $all_PhysicalSite | Where-Object {$_.name -eq $all_PhysicalSite.name}
$machineList = Get-AzureMigrateMachineList -Token $token -SubscriptionID $SubscriptionID -SiteName $vmwaresite_selected.'Site Name' -ResourceGroup $rg
#$health = Get-AzureMigrateVMwareHealthSiteSummary -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $vmwaresite_selected.'Site Name'
#$vmwaresite_selected = Get-AzureMigrateVMWareSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Sitename $vmwaresite_selected.'Site Name'
#$heartbeat = $vmwaresite_selected.Properties.agentDetails.lastHeartBeatUtc
$powerstate = $machinelist.properties | Select-Object vmFqdn, powerStatus
}
$ImportSite = Get-AzureMigrateImportSite -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -ProjectName $project_name
#Get Machine Stats
$discoveredmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
$discoveredSQLmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -SQL
$discoveredAVSmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -AVS
$discoveredCSVmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -Import
$discoveredIISmachines = Get-AzureMigrateDiscoveredMachine -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -IIS
if ($discoveredmachines.count -ge 1000) {
Write-host "More then 1000 VM Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeVM = "Weekly"
}
elseif ($discoveredmachines.count -lt 1000) {
$timerangeVM = "Monthly"
}
if ($discoveredCSVmachines.count -ge 1000) {
Write-host "More then 1000 CSV Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeCSV = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeCSV = "Monthly"
}
if ($discoveredSQLmachines.count -ge 1000) {
Write-host "More then 1000 SQL Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeSQL = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeSQL = "Monthly"
}
}
###
$quit = "no"
while ($quit -ne "yes") {
$assessment_output_choices =@(
"Project Stats"
"Create / refresh assessments and download them for all machines"
"Generate Tagging Sheet"
"Generate Health State Infomation"
"Populate Scope Groups"
"Create / refresh assessments and download them for Scope machines"
#"Populate Production/Non Prodction Groups",
#"Create / refresh assessments and download them for Production/Non Production machines",
#"Create Assessments from Group"
#"Download Assessments from Group"
"Get Full API Data (EnumerateMachines)"
#"Create Assessments (14 VM, 6 SQL)"
"Upload Data to Customer Blob"
"Open Customer Folder"
"######Advanced Settings#####"
"Download Assessments from Group"
"Remove Assessments from Group"
#"Remove Outdated Assessments"
"Remove All VM Assessments"
"Remove All SQL Assessments"
"Quit"
)
Set-Location $folder_path
$assessment_output_choices = $assessment_output_choices | Out-ConsoleGridView -Title "Assessment output options" -OutputMode Single
if ($assessment_output_choices -eq $null) { exit }
#Set Elements to faluse
$Project_Stats= $false
$Create_refresh_assessments_download_all_machine = $false
$Generate_Tagging_Sheet = $false
$Generate_Health_State_Infomation = $false
$Populate_Scope_Groups = $false
$Create_refresh_assessments_download_Scope_machines = $false
$Enable_Depdedancy= $false
$Export_Full_API_Dump= $false
#Advanced Start##
$Create_Assessments_from_Group= $false
$Remove_Assessments_from_Group= $false
$Download_Assessments_from_Group= $false
$Remove_Outdated_Assessments = $false
$Remove_All_VM_Assessments = $false
$Remove_All_SQL_Assessments = $false
$CreateSQLAssessments = $false
$CreateVMAssessments = $false
Clear-Host
switch ($assessment_output_choices)
{
"Project Stats"{$project_Stats = $true ;Set-Location $folder_path}
"Create / refresh assessments and download them for all machines"{$Create_refresh_assessments_download_all_machine = $true}
"Generate Tagging Sheet"{$Generate_Tagging_Sheet =$true;Set-Location $folder_path}
"Generate Health State Infomation"{$Generate_Health_State_Infomation = $true}
"Populate Scope Groups"{$Populate_Scope_Groups =$true;Set-Location $folder_path}
"Create / refresh assessments and download them for Scope machines"{$Create_refresh_assessments_download_Scope_machines = $true }
#"Populate Production/Non Prodction Groups"{}
#"Create / refresh assessments and download them for Production/Non Production machines"{}
#"Create Assessments from Group"{}
"Upload Data to Customer Blob"{$Uplaod_Data_to_Customer_Blob = $true}
"Enable Application Depdedancy"{$Enable_Depdedancy=$true}
"Get Full API Data (EnumerateMachines)"{$Export_Full_API_Dump = $true}
"Create SQL Assessments"{$CreateSQLAssessments=$true}
"Open Customer Folder"{Write-Host "The last Export date was $($dts_stamp)";Invoke-Item $path_to_Customers_folder\$containername}
"Quit"{$quit = "y";exit}
Default {Write-Host "Incorrect input. Closing script in 10 seconds" ; Start-Sleep -s 10 ; exit}
}
#ProjectStats
if ($Project_Stats -eq $true) {
Write-host "Project Stats:"
if ($discoveredmachines.count -ge 1) {
Write-Host "There are the $($discoveredmachines.Count) Virtual Machines that have been discovered" -ForegroundColor Yellow
}
if ($discoveredCSVmachines.count -ge 1) {
Write-Host "There are the $($discoveredCSVmachines.Count) CSV Import Machines that have been discovered" -ForegroundColor Yellow
}
if ($discoveredSQLmachines.count -ge 1) {
Write-Host "There are the $($discoveredSQLmachines.Count) SQL Machines that have been discovered" -ForegroundColor Yellow
$sqlsite = Get-AzureMigrate-SQLSite -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_name -MasterSiteName $mastersite_selected.name
$SQLInstances = Get-AzureMigrate-SQLDiscovervedInstances -Token $token -SubscriptionID $SubscriptionID -ResoruceGroup $rg -ProjectName $project_friendly_name -MasterSiteName $mastersite_selected.name -APIVersion 2020-11-11-preview -SQLSiteName $sqlsite.name
}
if ($discoveredAVSmachines.count -ge 1) {
Write-Host "There are the $($discoveredAVSmachines.Count) AVS Machines that have been discovered" -ForegroundColor Yellow
}
}
#Create / refresh assessments and download them for all machines
if ($Create_refresh_assessments_download_all_machine -eq $true) {
$token = Get-AzCachedAccessToken
#"Create / refresh assessments and download them for all machines"
#Required Actions
$AzMigGroups = Get-AzureMigrateGroups -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
#Create Groups - All VM - All SQL
#Populate Groups - All VM - All SQL
Write-Host "Creating VM Groups" -ForegroundColor Cyan
if ($discoveredmachines.count -ne 0) {
$All_Machines_Group = New-AzureMigrateGroupAddMachines -token $token -subscriptionId $SubscriptionID -resourceGroupName $rg -assessmentProjectName $project_name -discoverySource "Appliance" -groupName "All_Machines"
}
else {
Write-Host "There are no VM Servers - Skipping" -ForegroundColor Cyan
}
if ($discoveredSQLmachines.count -ne 0) {
$All_Machines_SQL_Group = New-AzureMigrateGroupAddMachines -token $token -subscriptionId $SubscriptionID -resourceGroupName $rg -assessmentProjectName $project_name -discoverySource "SQL" -groupName "All_Machines_SQL"
}
else {
Write-Host "There are no SQL Servers - Skipping" -ForegroundColor Cyan
}
if ($discoveredCSVmachines.count -ne 0) {
$All_Machines_CSV_Group = New-AzureMigrateGroupAddMachines -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -assessmentProjectName $project_name -GroupName "All_Machines_CSV" -discoverySource "Import"
}
else {
Write-Host "There are no CSV Servers - Skipping" -ForegroundColor Cyan
}
Write-host "Waiting for Groups to be Created"
$groupStatus = Get-AzureMigrateGroups -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
while ($groupStatus -eq "Running" -or $groupStatus-eq "Updated" -or $groupStatus -eq "Created") {
Start-Sleep -Seconds 60
$AzMigGroups = Get-AzureMigrateGroups -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
[math]::Round($stopwatch.Elapsed.TotalMinutes,1).ToString() + " minutes"
}
$stopwatch.Stop()
Write-Host "Refreshing Token" -ForegroundColor Green
$token = Get-AzCachedAccessToken
if ($discoveredmachines.count -ge 1000) {
Write-host "More then 1000 VM Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeVM = "Weekly"
}
elseif ($discoveredmachines.count -lt 1000) {
$timerangeVM = "Monthly"
}
if ($discoveredCSVmachines.count -ge 1000) {
Write-host "More then 1000 CSV Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeCSV = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeCSV = "Monthly"
}
if ($discoveredSQLmachines.count -ge 1000) {
Write-host "More then 1000 SQL Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeSQL = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeSQL = "Monthly"
}
Set-location $folder_path
#Create 14 Assessmsnets - VM
$token = Get-AzCachedAccessToken
if ($discoveredmachines.count -ne 0) {
Write-host "Begin Creating VM Assessments" -ForegroundColor Cyan
Create-Bulk-VM-Assessments -Token $token -SubscriptionID $SubscriptionID -ProjectName $project_name -groupname "All_Machines" -ResourceGroup $rg -discoverySource Appliance -timerange $timerangeVM
}
$token = Get-AzCachedAccessToken
if ($discoveredCSVmachines.count -ne 0) {
Write-host "Begin Creating CSV Assessments" -ForegroundColor Cyan
Create-Bulk-VM-Assessments -Token $token -SubscriptionID $SubscriptionID -ProjectName $project_name -groupname "All_Machines_CSV" -ResourceGroup $rg -discoverySource Import timerangeCSV $timerangeCSV
}
Set-location $folder_path
#Create 6 Assessments - SQL
$token = Get-AzCachedAccessToken
if ($discoveredSQLmachines.count -ne 0) {
Write-host "Begin Creating SQL Assessments" -ForegroundColor Cyan
Create-Bulk-SQL-Assessments -Token $token -SubscriptionID $SubscriptionID -ProjectName $project_name -groupname "All_Machines_SQL" -ResourceGroup $rg -discoverySource Appliance -timerange $timerangeSQL
}
elseif ($discoveredSQLmachines.count -eq 0) {
Write-Host "There are no SQL Servers - not creating Assessments" -ForegroundColor Cyan
}
$token = Get-AzCachedAccessToken
$assessments = Get-AzureMigrateAssessments -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
$VMassessments = $assessments | where-object {$_.properties.AssessmentType -eq "MachineAssessment" -and $_.properties.groupType -ne "Import"} | Select-Object @{N="Group"; E={"All Machines"}}, @{N="Assessment Name"; E={$_.name}}, @{N="Assessment Type"; E={$_.properties.assessmentType}},@{N="Status"; E={$_.properties.status}}
$SQLassessments = $assessments | where-object {$_.properties.AssessmentType -eq "SqlAssessment"} | Select-Object @{N="Group"; E={"All SQL Machines"}}, @{N="Assessment Name"; E={$_.name}}, @{N="Assessment Type"; E={$_.properties.assessmentType}},@{N="Status"; E={$_.properties.status}}
$CSVassessments = $assessments | where-object {$_.properties.groupType -eq "Import"} | Select-Object @{N="Group"; E={"All CSV Machines"}}, @{N="Assessment Name"; E={$_.name}}, @{N="Assessment Type"; E={$_.properties.assessmentType}},@{N="Status"; E={$_.properties.status}}
#Export 14 Assessments - VM
if ($VMassessments.count -ge 1) {
$groupname = "All_Machines"
$token = Get-AzCachedAccessToken
$Output_VMAssessments_All_Machines = "$path_to_Customers_folder\$($containername)\VM Assessments\$($dts_stamp)"
If(Test-Path $Output_VMAssessments_All_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_VMAssessments_All_Machines }
Set-location $Output_VMAssessments_All_Machines
Export-Bulk-VM-Assessments -SubscriptionID $SubscriptionID -ProjectName $project_name -ResourceGroup $rg -groupname $groupname -Token $token
Write-host "Exporting Assessment JSON Outputs" -Force Cyan
$Output_VMAssessments_All_Machines = "$path_to_Customers_folder\$($containername)\VM Assessments\$($dts_stamp)\JSON"
If(Test-Path $Output_VMAssessments_All_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_VMAssessments_All_Machines }
Set-location $Output_VMAssessments_All_Machines
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 3 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "As is 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is PAYG" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is PAYG_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is PAYG AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is PAYG AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "Perf 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 3 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 3 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 1 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 1 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG - Premium Disks" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\JSON\$dts_stamp\Perf PAYG - Premium Disks_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG - Standard Disks" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\JSON\$dts_stamp\Perf PAYG - Standard Disks_$($groupname).json"
}
$token = Get-AzCachedAccessToken
#Export 14 Assessments - CSV
if ($CSVassessments.count -ge 1) {
Write-host "Exporting Assessment JSON Outputs" -Force Cyan
$Output_VMAssessments_All_Machines = "$path_to_Customers_folder\$($containername)\VM Assessments\$($dts_stamp)"
If(Test-Path $Output_VMAssessments_All_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_VMAssessments_All_Machines }
Set-location $Output_VMAssessments_All_Machines
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 1 Year RI AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 1 Year RI AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 3 Year RI_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 3 Year RI AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "As is 3 Year RI AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is PAYG_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is PAYG_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is PAYG AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is PAYG AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 3 Year RI AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "Perf 1 Year RI AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 3 Year RI_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 3 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 1 Year RI_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 1 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG AHUB_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG - Premium Disks_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG - Premium Disks_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG - Standard Disks_CSV" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG - Standard Disks_$($groupname).json"
Write-host "Exporting Assessment CSV Outputs" -Force Cyan
$groupname = "All_Machines_CSV"
$token = Get-AzCachedAccessToken
$Output_VMAssessments_CSV_Machines = "$path_to_Customers_folder\$($containername)\VM Assessments\+$($dts_stamp)\JSON"
If(Test-Path $Output_VMAssessments_CSV_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_VMAssessments_CSV_Machines }
Set-location $Output_VMAssessments_CSV_Machines
Export-Bulk-VM-Assessments -SubscriptionID $SubscriptionID -ProjectName $project_name -ResourceGroup $rg -groupname $groupname -Token $token -CSV
}
$token = Get-AzCachedAccessToken
#Export 6 Assessments - SQL
if ($SQLassessments.count -ge 1) {
$groupname= "All_Machines_SQL"
$token = Get-AzCachedAccessToken
$Output_All_Machines_SQL_Machines = "$($path_to_Customers_folder)\$($containername)\SQL Assessments\$($dts_stamp)"
If(Test-Path $Output_All_Machines_SQL_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_All_Machines_SQL_Machines }
Set-location $Output_All_Machines_SQL_Machines
Export-Bulk-SQL-Assessments -SubscriptionID $SubscriptionID -ProjectName $project_name -ResourceGroup $rg -groupname $groupname -Token $token
Write-host "Exporting Assessment JSON Outputs" -Force Cyan
$Output_All_Machines_SQL_Machines = "$($path_to_Customers_folder)\$($containername)\SQL Assessments\+$($dts_stamp)\JSON"
If(Test-Path $Output_All_Machines_SQL_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_All_Machines_SQL_Machines }
Set-location $Output_All_Machines_SQL_Machines
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\SQL_Perf 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 1 Year RI" | ConvertTo-Json -Depth 100 |Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\SQL_Perf 1 Year RI_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 3 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\SQL_Perf 3 Year RI_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\SQL_Perf 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf PAYG" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\SQL_Perf PAYG_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf PAYG AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\SQL_Perf PAYG AHUB_$($groupname).json"
# Action to perform if the condition is true #>
}
$token = Get-AzCachedAccessToken
cls
}
#Generate Tagging Sheet
if ($Generate_Tagging_Sheet -eq $true) {
Set-Location $path_to_Customers_folder\$containername\'API Infomation'
If(Test-Path $dts_stamp) { "Output Folder Present" } Else { new-item -ItemType Directory -path $dts_stamp }
Set-location $dts_stamp
#"Generate Tagging Sheet",
Write-Host "Exporting VM Scope File" -ForegroundColor Yellow
Create-VM-Scope-Output -Output "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp"
if ($discoveredSQLmachines.count -ge 1) {
Write-Host "Exporting SQL Scope File" -ForegroundColor Yellow
Create-SQL-Scope-Output "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp"
}
else
{
Write-Host "No SQL Machines found - Not Generating Tagging"
}
$token = Get-AzCachedAccessToken
}
#Generate Health State Infomation
if ($Generate_Health_State_Infomation -eq $true) {
#"Gather Health State Infomation",
$token = Get-AzCachedAccessToken
<# Action to perform if the condition is true #>
$Output_API_Infomation = "$($path_to_Customers_folder)\$($containername)\API Infomation\"
If(Test-Path $Output_API_Infomation) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_API_Infomation }
Set-location $Output_API_Infomation
Write-Host "Exporting Health State Infomation" -ForegroundColor Green
$jsonmachine = $machineList | ConvertTo-Json -Depth 100 | out-file machinelist.json
$jsonhealth = $health | ConvertTo-Json -Depth 100 | out-file healthsitesummary.json
$jsonsqlinstances = $SQLInstances | ConvertTo-Json -Depth 100 | out-file Discovered_SQL_Instances.json
$discoveredmachines | ConvertTo-Json -Depth 100 | out-file Discovered_VMs.json
$discoveredSQLmachines | ConvertTo-Json -Depth 100 | out-file Discovered_SQL_Machine.json
$stats = Get-AzureMigrateProjectStats -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
$stats | ConvertTo-Json -Depth 100 | out-file ProjectInfo.json
}
#Populate Scope Groups
if ($Populate_Scope_Groups -eq $true) {
$token = Get-AzCachedAccessToken
$VMtagging = Import-Csv -Path "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\VMScope.csv"
Read-host "Please Update the VM Scope File with In/Out of Scope deffintions"
ii .\VMScope.csv
$VMtagging = Import-Csv -Path "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\VMScope.csv"
$inscopevm = $VMtagging | Where-Object 'In/Out of Scope' -Like "In Scope"
$inscopevm | export-csv "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\VMScope.csv"
$SQLtagging = Import-Csv -Path "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\SQLScope.csv"
Read-host "Please Update the SQL Scope File with In/Out of Scope deffintions"
ii .\SQLScope.csv
$SQLtagging = Import-Csv -Path "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\SQLScope.csv"
$inscopeSQL = $SQLtagging | Where-Object 'In/Out of Scope' -Like "In Scope"
$inscopeSQL | export-csv "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\SQLScope.csv"
$token = Get-AzCachedAccessToken
#"Populate Scope Groups",
$VM_in_Scope_Group = New-AzureMigrateGroup -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName "VM_in_Scope"
if ($discoveredSQLmachines -eq 0) {
Write-Host "There are no SQL Servers - Skipping" -ForegroundColor Cyan
}
else {
$SQL_In_Scope_Group = New-AzureMigrateGroup -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName "SQL_In_Scope"
}
Write-Host $nl
#Offer Option to Select VM ScopeFile
if ($inscopevm.count -ne 0) {
$groupname = "VM_in_Scope"
$inscopemachines = Import-Csv "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\VMScope.csv"
Write-Host "Adding Machines to VM Scope Group" -ForegroundColor Cyan
Set-AzureMigrateGroup -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -Group $groupname -Machines $inscopemachines.id -Add
}
else {
Write-Host "Please select the VM Scope file that you wish to update the VMScope Group with"
$vmscopefile = Get-File
$inscopemachines = Import-Csv $vmscopefile
$groupname = "VM_in_Scope"
Write-Host "Adding Machines to VM Scope Group" -ForegroundColor Cyan
Set-AzureMigrateGroup -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -Group $groupname -Machines $inscopemachines -Add
}
if ($inscopeSQL.count -ne 0) {
$groupname = "SQL_in_Scope"
$inscopemachines = Import-Csv "$path_to_Customers_folder\$containername\API Infomation\$dts_stamp\SQLScope.csv"
Write-Host "Adding Machines to SQL Scope Group" -ForegroundColor Cyan
Set-AzureMigrateGroup -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -Group $groupname -Machines $inscopemachines.id -Add
}
else {
Write-Host "Please select the VM Scope file that you wish to update the VMScope Group with"
$SQLscopefile = Get-File
$inscopemachines = Import-Csv $SQLscopefile
$groupname = "SQL_in_Scope"
Write-Host "Adding Machines to SQL Scope Group" -ForegroundColor Cyan
Set-AzureMigrateGroup -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -Group $groupname -Machines $inscopemachines -Add
}
#Check for Status
$AzMigGroups = Get-AzureMigrateGroups -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
while ($groupStatus.Contains('Running') -or $groupStatus.Contains('Updated') -or $groupStatus.Contains('Created')) {
Start-Sleep -Seconds 60
$AzMigGroups = Get-AzureMigrateGroups -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
[math]::Round($stopwatch.Elapsed.TotalMinutes, 1).ToString() + ' minutes'
}
$stopwatch.Stop()
}
#Create / refresh assessments and download them for Scope machines
if ($Create_refresh_assessments_download_Scope_machines -eq $true) {
New-Item -Path "$path_to_Customers_folder\$($containername)\VM Assessments\$($dts_stamp)" -Name "ScopedVMExport.txt" -Force
$token = Get-AzCachedAccessToken
#"Create / refresh assessments and download them for all machines"
#Required Actions
Write-Host "Refreshing Token" -ForegroundColor Green
$token = Get-AzCachedAccessToken
if ($discoveredmachines.count -ge 1000) {
Write-host "More then 1000 VM Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeVM = "Weekly"
}
elseif ($discoveredmachines.count -lt 1000) {
$timerangeVM = "Monthly"
}
if ($discoveredSQLmachines.count -ge 1000) {
Write-host "More then 1000 SQL Machines dectected, Setting Assessment Time Range to Weekly to impove peformance" -ForegroundColor Red
$timerangeSQL = "Weekly"
}
elseif ($discoveredCSVmachines.count -lt 1000) {
$timerangeSQL = "Monthly"
}
Set-location $folder_path
#Create 14 Assessmsnets - VM
$token = Get-AzCachedAccessToken
if ($discoveredmachines.count -ne 0) {
Write-host "Begin Creating VM Assessments" -ForegroundColor Cyan
Create-Bulk-VM-Assessments -Token $token -SubscriptionID $SubscriptionID -ProjectName $project_name -groupname "VM_in_Scope" -ResourceGroup $rg -discoverySource Appliance -timerange $timerangeVM
}
$token = Get-AzCachedAccessToken
Set-location $folder_path
#Create 6 Assessments - SQL
$token = Get-AzCachedAccessToken
if ($discoveredSQLmachines.count -ne 0) {
Write-host "Begin Creating SQL Assessments" -ForegroundColor Cyan
Create-Bulk-SQL-Assessments -Token $token -SubscriptionID $SubscriptionID -ProjectName $project_name -groupname "SQL_In_Scope" -ResourceGroup $rg -discoverySource Appliance -timerange $timerangeSQL
}
elseif ($discoveredSQLmachines.count -eq 0) {
Write-Host "There are no SQL Servers - not creating Assessments" -ForegroundColor Cyan
}
$token = Get-AzCachedAccessToken
$assessments = Get-AzureMigrateAssessments -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name
$VMassessments = $assessments | where-object {$_.properties.AssessmentType -eq "MachineAssessment" -and $_.properties.groupType -ne "Import"} | Select-Object @{N="Group"; E={"All Machines"}}, @{N="Assessment Name"; E={$_.name}}, @{N="Assessment Type"; E={$_.properties.assessmentType}},@{N="Status"; E={$_.properties.status}}
$SQLassessments = $assessments | where-object {$_.properties.AssessmentType -eq "SqlAssessment"} | Select-Object @{N="Group"; E={"All SQL Machines"}}, @{N="Assessment Name"; E={$_.name}}, @{N="Assessment Type"; E={$_.properties.assessmentType}},@{N="Status"; E={$_.properties.status}}
$CSVassessments = $assessments | where-object {$_.properties.groupType -eq "Import"} | Select-Object @{N="Group"; E={"All CSV Machines"}}, @{N="Assessment Name"; E={$_.name}}, @{N="Assessment Type"; E={$_.properties.assessmentType}},@{N="Status"; E={$_.properties.status}}
#Export 14 Assessments - VM
if ($VMassessments.count -ge 1) {
#Downlaod JSON Files
Write-host "Exporting Assessment JSON Outputs" -Force Cyan
$Output_VMAssessments_All_Machines = "$path_to_Customers_folder\$($containername)\VM Assessments\$($dts_stamp)\JSON"
If(Test-Path $Output_VMAssessments_All_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_VMAssessments_All_Machines }
Set-location $Output_VMAssessments_All_Machines
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 3 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "As is 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is PAYG" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is PAYG_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "As is PAYG AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\As is PAYG AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -Token $token -SubscriptionID $SubscriptionID -ResourceGroup $rg -Project $project_name -GroupName $groupname -assessmentname "Perf 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 3 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 3 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf 1 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf 1 Year RI_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\$dts_stamp\JSON\Perf PAYG AHUB_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG - Premium Disks" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\JSON\$dts_stamp\Perf PAYG - Premium Disks_$($groupname).json"
Get-AzureMigrateAssessedMachines-by-Assessment -subscriptionId $subscriptionid -ResourceGroup $rg -Project $project_name -groupName $groupname -token $token -assessmentName "Perf PAYG - Standard Disks" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\VM Assessments\JSON\$dts_stamp\Perf PAYG - Standard Disks_$($groupname).json"
#Download XLS Files
Write-host "Exporting Assessment XLS Outputs" -Force Cyan
$groupname = "VM_in_Scope"
$token = Get-AzCachedAccessToken
$Output_VMAssessments_All_Machines = "$path_to_Customers_folder\$($containername)\VM Assessments\$($dts_stamp)"
If(Test-Path $Output_VMAssessments_All_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_VMAssessments_All_Machines }
Set-location $Output_VMAssessments_All_Machines
Export-Bulk-VM-Assessments -SubscriptionID $SubscriptionID -ProjectName $project_name -ResourceGroup $rg -groupname $groupname -Token $token
}
$token = Get-AzCachedAccessToken
#Export 6 Assessments - SQL
if ($SQLassessments.count -ge 1) {
$jsonsqlinstances = $SQLInstances | ConvertTo-Json -Depth 100 | out-file Discovered_SQL_Instances.json
Write-host "Exporting Assessment JSON Outputs" -Force Cyan
$Output_All_Machines_SQL_Machines = "$($path_to_Customers_folder)\$($containername)\SQL Assessments\+$($dts_stamp)\JSON"
If(Test-Path $Output_All_Machines_SQL_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_All_Machines_SQL_Machines }
Set-location $Output_All_Machines_SQL_Machines
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 1 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\SQL Assessments\$dts_stamp\JSON\SQL_Perf 1 Year RI AHUB_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 1 Year RI" | ConvertTo-Json -Depth 100 |Out-File "$path_to_Customers_folder\$containername\SQL Assessments\$dts_stamp\JSON\SQL_Perf 1 Year RI_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 3 Year RI" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\SQL Assessments\$dts_stamp\JSON\SQL_Perf 3 Year RI_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf 3 Year RI AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\SQL Assessments\$dts_stamp\JSON\SQL_Perf 3 Year RI AHUB_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf PAYG" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\SQL Assessments\$dts_stamp\JSON\SQL_Perf PAYG_$($groupname).json"
Get-AzureMigrate-SQLDiscovervedDatabases -Token $token -SubscriptionID $subscriptionid -ResoruceGroup $rg -ProjectName $project_name -groupname $groupname -assessmentname "SQL_Perf PAYG AHUB" | ConvertTo-Json -Depth 100 | Out-File "$path_to_Customers_folder\$containername\SQL Assessments\$dts_stamp\JSON\SQL_Perf PAYG AHUB_$($groupname).json"
Write-host "Exporting Assessment XLS Outputs" -Force Cyan
$groupname= "SQL_in_Scope"
$token = Get-AzCachedAccessToken
$Output_All_Machines_SQL_Machines = "$($path_to_Customers_folder)\$($containername)\SQL Assessments\"+$($dts_stamp)
If(Test-Path $Output_All_Machines_SQL_Machines) { "Output Folder Present" } Else { new-item -ItemType Directory -path $Output_All_Machines_SQL_Machines }
Set-location $Output_All_Machines_SQL_Machines
Export-Bulk-SQL-Assessments -SubscriptionID $SubscriptionID -ProjectName $project_name -ResourceGroup $rg -groupname $groupname -Token $token
# Action to perform if the condition is true #>
}
$token = Get-AzCachedAccessToken
cls
}
#Enable Depdedancy
if ($Enable_Depdedancy -eq $true) {
$token = Get-AzCachedAccessToken
#Get List of VMs
Set-Location $path_to_Customers_folder\$containername\'API Infomation'
If(Test-Path $dts_stamp) { "Output Folder Present" } Else { new-item -ItemType Directory -path $dts_stamp }
Set-location $dts_stamp
$output = new-item -ItemType Directory -Path "Depdendancy Output" -Force
Get-AzMigDiscoveredVMwareVMs -ResourceGroupName $rg -ProjectName $project_friendly_name -OutputCsvFile "$output/Application_Depednacy_Discovered_VMs.csv"
$file = Get-Content "$output/Application_Depednacy_Discovered_VMs.csv"
if($file.count -gt 1000)
{Write-host "More then 1000 machines in file, splitting file in to chunks"
$InputFilename = Get-Content 'Application_Depednacy_Discovered_VMs.csv'
$OutputFilenamePattern = 'output_done_'
$LineLimit = 1000
$line = 0
$i = 0
$file = 0
$start = 0
while ($line -le $InputFilename.Length) {
if ($i -eq $LineLimit -Or $line -eq $InputFilename.Length) {
$file++
$Filename = "$OutputFilenamePattern$file.csv"
$InputFilename[$start..($line-1)] | Out-File "$output/$Filename" -Force
$start = $line;
$i = 0
Write-Host "$Filename"
}
$i++;
$line++
}
Set-Location $path_to_Customers_folder\$containername\'API Infomation'\$dts_stamp\'Depdendancy Output'
$inputfiles = Get-ChildItem '.\' -Filter *.csv
foreach ($file in $inputfiles) {