3
3
4
4
Set-Variable - Name AMH_APIVERSION - Value " ?api-version=2018-09-01-preview" - Option Constant - Scope Script - Force
5
5
Set-Variable - Name SDS_APIVERSION - Value " ?api-version=2020-01-01" - Option Constant - Scope Script - Force
6
+ Set-Variable - Name HyperVandServer_APIVERSION - Value " ?api-version=2020-08-01-preview" - Option Constant - Scope Script - Force
6
7
Set-Variable - Name SAS_APIVERSION - Value " ?api-version=2019-10-01" - Option Constant - Scope Script - Force
7
8
Set-Variable - Name RSV_APIVERSION - Value " ?api-version=2018-07-10" - Option Constant - Scope Script - Force
8
9
@@ -156,16 +157,13 @@ function Get-AzMigDiscoveredVMwareVMs {
156
157
throw " Server Discovery Solution missing Appliance Details. Invalid Solution."
157
158
}
158
159
159
-
160
-
161
-
162
160
$vmwareappliancemap = @ {}
163
161
# Discard non-VMware appliances
164
162
# If Appliance name is passed get data only for that appliance
165
163
# If Appliance name is not passed , get data for all appliances in that project
166
164
if (-not $ApplianceName ){
167
- $appMap.GetEnumerator () | foreach {if ($_.Value -match " VMwareSites" ) {$vmwareappliancemap [$_.Key ] = $_.Value }}}else {
168
- $appMap.GetEnumerator () | foreach {if ($_.Value -match " VMwareSites" -and $_.Key -eq $ApplianceName ) {$vmwareappliancemap [$_.Key ] = $_.Value }}}
165
+ $appMap.GetEnumerator () | foreach {if ($_.Value -match " VMwareSites|HyperVSites|ServerSites " ) {$vmwareappliancemap [$_.Key ] = $_.Value }}}else {
166
+ $appMap.GetEnumerator () | foreach {if ($_.Value -match " VMwareSites|HyperVSites|ServerSites " -and $_.Key -eq $ApplianceName ) {$vmwareappliancemap [$_.Key ] = $_.Value }}}
169
167
Write-Debug $vmwareappliancemap.count
170
168
if ($vmwareappliancemap ) {$vmwareappliancemap | Out-String | Write-Debug };
171
169
if (-not $vmwareappliancemap.count ) {throw " No VMware VMs discovered in project" };
@@ -176,7 +174,11 @@ function Get-AzMigDiscoveredVMwareVMs {
176
174
foreach ($item in $vmwareappliancemap.GetEnumerator ()) {
177
175
$SiteId = $item.Value ;
178
176
Write-Debug " Get machines for Site $SiteId "
179
- $requesturi = $Properties [' baseurl' ] + $SiteId + " /machines" + $SDS_APIVERSION + " &`$ top=400"
177
+ if ($SiteId -match " (/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" -or $SiteId -match " (/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" ){
178
+ $requesturi = $Properties [' baseurl' ] + $SiteId + " /machines" + $HyperVandServer_APIVERSION + " &`$ top=400" }
179
+ if ($SiteId -match " (/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)" ){
180
+ $requesturi = $Properties [' baseurl' ] + $SiteId + " /machines" + $SDS_APIVERSION + " &`$ top=400" }
181
+
180
182
181
183
# Write-Host $requesturi
182
184
@@ -209,7 +211,6 @@ function Get-AzMigDiscoveredVMwareVMs {
209
211
}
210
212
}
211
213
212
-
213
214
if ($DiscoveredMachines.count -gt 0 ) {
214
215
215
216
$DiscoveredMachines | Select-Object - Property @ { expression = {$_.properties.displayName }; label = ' VM display name' }, @ { expression = {$_.properties.dependencymapping }; label = ' Current status' }, @ { expression = {$_.id }; label = ' ARM ID' } | Export-Csv - NoTypeInformation - Path $OutputCsvFile
@@ -254,9 +255,11 @@ function Set-AzMigDependencyMappingAgentless {
254
255
255
256
if ($Enable )
256
257
{
257
- $ActionVerb = " Enabled"
258
+ $ActionVerb = " Enabled" ;
259
+ $EnableDependencyMapping = $true ;
258
260
} elseif ($Disable ) {
259
- $ActionVerb = " Disabled"
261
+ $ActionVerb = " Disabled" ;
262
+ $EnableDependencyMapping = $false ;
260
263
} else {
261
264
throw " Error"
262
265
}
@@ -283,7 +286,6 @@ function Set-AzMigDependencyMappingAgentless {
283
286
$currentsite = $null
284
287
foreach ($machine in $VMs ) {
285
288
if (-not ($machine -match " (/subscriptions/.*\/VMwareSites/([^\/]*)\w{4}site)" )) {
286
- Write-Debug " Skipping $machine "
287
289
continue ;
288
290
}
289
291
@@ -347,8 +349,86 @@ function Set-AzMigDependencyMappingAgentless {
347
349
else {
348
350
throw " Could not update dependency mapping status for input VMs on appliance: $appliancename "
349
351
}
352
+ }
353
+
354
+ # Reset jsonpayload and loop through the same machines , this time for hyperV and server fabric
355
+ $jsonPayload.machines = @ ();
356
+
357
+ $currentsite = $null
358
+ foreach ($machine in $VMs ) {
359
+ if (-not ($machine -match " (/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $machine -match " (/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" )) {
360
+ continue ;
361
+ }
362
+
363
+ $sitename = $Matches [1 ];
364
+ Write-Debug " Site: $sitename Machine: $machine " ;
365
+
366
+ if ((-not $currentsite ) -or ($sitename -eq $currentsite )) {
367
+ $currentsite = $sitename ;
368
+ $tempobj = [PSCustomObject ]@ {
369
+ machineId = $machine
370
+ isDependencyMapToBeEnabled = $EnableDependencyMapping
371
+ }
372
+ $jsonPayload.machines += $tempobj ;
373
+ continue ;
374
+ }
375
+
376
+ # different site. Send update request for previous site and start building request for the new site
377
+ if ($sitename -ne $currentsite ) {
378
+ if ($jsonPayload.machines.count ) {
379
+ $requestbody = $jsonPayload | ConvertTo-Json
380
+ $requestbody | Write-Debug
381
+ $requesturi = $Properties [' baseurl' ] + ${currentsite} + " /UpdateDependencyMapStatus" + $HyperVandServer_APIVERSION ;
382
+ Write-Debug " request uri is : $requesturi "
383
+ $response = $null
384
+ $response = Invoke-RestMethod - Method Post - Headers $Properties [' Headers' ] - Body $requestbody $requesturi - ContentType " application/json"
385
+ if ($response ) {
386
+ $temp = $currentsite -match " \/([^\/]*)\w{4}site$" # Extract the appliance name
387
+ $appliancename = $Matches [1 ]
388
+ Write-Output " Updated dependency mapping status for input VMs on appliance: $appliancename "
389
+ }
390
+ else {
391
+ throw " Could not update dependency mapping status"
392
+ }
393
+ }
394
+
395
+ # Reset jsonpayload
396
+ $jsonPayload.machines = @ ();
397
+ $tempobj = [PSCustomObject ]@ {
398
+ machineId = $machine
399
+ isDependencyMapToBeEnabled = $EnableDependencyMapping
400
+ }
401
+ $jsonPayload.machines += $tempobj ;
402
+ $currentsite = $sitename # update current site name
403
+ }
350
404
}
351
405
406
+
407
+ # Enable/Disable dependency for unprocessed sites
408
+ if ($jsonPayload.machines.count ) {
409
+ $requestbody = $jsonPayload | ConvertTo-Json
410
+ $requestbody | Write-Debug
411
+ $requesturi = $Properties [' baseurl' ] + ${currentsite} + " /UpdateDependencyMapStatus" + $HyperVandServer_APIVERSION ;
412
+ Write-Debug $requesturi
413
+ $response = $null
414
+ $response = Invoke-RestMethod - Method Post - Headers $Properties [' Headers' ] - Body $requestbody $requesturi - ContentType " application/json"
415
+ $temp = $currentsite -match " \/([^\/]*)\w{4}site$" # Extract the appliance name
416
+ $appliancename = $Matches [1 ]
417
+ if ($response ) {
418
+ Write-Output " Updating dependency mapping status for input VMs on appliance: $appliancename "
419
+ }
420
+ else {
421
+ throw " Could not update dependency mapping status for input VMs on appliance: $appliancename "
422
+ }
423
+ }
424
+
425
+ # Pointing out all the incorrect ARM IDs
426
+ foreach ($machine in $VMs ) {
427
+ if (-not ($machine -match " (/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $machine -match " (/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" -or $machine -match " (/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)" )) {
428
+ Write-Output " Skipping the machine : $machine . Please check the ARM ID"
429
+ }
430
+ }
431
+
352
432
}
353
433
Export-ModuleMember - Function Set-AzMigDependencyMappingAgentless
354
434
@@ -422,7 +502,13 @@ function Get-AzMigDependenciesAgentless {
422
502
return ;
423
503
}
424
504
425
- $url = $Properties [' baseurl' ] + $VMWareSiteID + " /exportDependencies?api-version=2020-01-01-preview"
505
+ Write-Output $VMWareSiteID
506
+
507
+ if ($VMWareSiteID -match " (/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)" ){
508
+ $url = $Properties [' baseurl' ] + $VMWareSiteID + " /exportDependencies?api-version=2020-01-01-preview" }
509
+
510
+ if ($VMWareSiteID -match " (/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $VMWareSiteID -match " (/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" ){
511
+ $url = $Properties [' baseurl' ] + $VMWareSiteID + " /exportDependencies?api-version=2020-08-01-preview" }
426
512
427
513
$StartTime = Get-Date
428
514
@@ -446,8 +532,11 @@ $jsonPayload = @"
446
532
throw " Could not retrieve the site for appliance $appliancename "
447
533
}
448
534
449
-
450
- $url = $Properties [' baseurl' ] + $response.id + " ?api-version=2020-01-01-preview"
535
+ if ($VMWareSiteID -match " (/subscriptions/.*\/VmwareSites/([^\/]*)\w{4}site)" ){
536
+ $url = $Properties [' baseurl' ] + $response.id + " ?api-version=2020-01-01-preview" }
537
+
538
+ if ($VMWareSiteID -match " (/subscriptions/.*\/HyperVSites/([^\/]*)\w{4}site)" -or $VMWareSiteID -match " (/subscriptions/.*\/ServerSites/([^\/]*)\w{4}site)" ){
539
+ $url = $Properties [' baseurl' ] + $response.id + " ?api-version=2020-08-01-preview" }
451
540
452
541
Write-Host " Please wait while the dependency data is downloaded..."
453
542
0 commit comments