Skip to content

Commit 79bbf7c

Browse files
authored
[Az.Migrate] Fix for kvspnid coming as Null for some users (Azure#21719)
* Fix for kvspnid coming as Null for some users * Fix of file encoding
1 parent f11c777 commit 79bbf7c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/Migrate/custom/Initialize-AzMigrateReplicationInfrastructure.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public static int hashForArtifact(String artifact)
356356
if ($CloudEnvironMent -eq "AzureUSGovernment") {
357357
$HyperVManagerAppId = "AFAE2AF7-62E0-4AA4-8F66-B11F74F56326"
358358
}
359-
$hyperVManagerObject = Get-AzADServicePrincipal -ApplicationID $HyperVManagerAppId
359+
$hyperVManagerObject = Get-AzADServicePrincipal -ApplicationID $HyperVManagerAppId
360360
$accessPolicies = @()
361361
$userAccessPolicy = @{
362362
"tenantId" = $tenantID;
@@ -449,7 +449,24 @@ public static int hashForArtifact(String artifact)
449449
# RoleAssignments
450450

451451
$roleDefinitionId = "81a9662b-bebf-436f-a333-f67b29880f12"
452-
$kvspnid = (Get-AzADServicePrincipal -DisplayName "Azure Key Vault" )[0].Id
452+
$kvspnid = Get-AzADServicePrincipal -DisplayName "Azure Key Vault"
453+
$Id = ""
454+
if($kvspnid -ne $null){
455+
$type = $kvspnid.GetType().BaseType
456+
Write-Host $type.Name
457+
if ($type.Name -eq "Array"){
458+
$Id = $kvspnid[0].Id
459+
}
460+
else{
461+
$Id = $kvspnid.Id
462+
}
463+
}
464+
else{
465+
Write-Host "Unable to retrieve KV SPN Id"
466+
}
467+
Write-Host $Id
468+
469+
$kvspnid = $Id
453470
$gwyStorageAccount = Get-AzResource -ResourceName $GateWayStorageAcName -ResourceGroupName $ResourceGroupName
454471
$lsaStorageAccount = Get-AzResource -ResourceName $LogStorageAcName -ResourceGroupName $ResourceGroupName
455472
$gwyRoleAssignments = Get-AzRoleAssignment -ObjectId $kvspnid -Scope $gwyStorageAccount.Id -ErrorVariable notPresent -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)