Open paul-e-martin opened 2 years ago
Deploying a new Image Builder template via PowerShell doesn't allow the addition of userAssignedIdentities to the VM. the option is in the json template, but gets removed when its deserialized. The same template works as expected via the Azure CLI.
# Build template # Destination image resource group name $imageResourceGroup = '' $identityName = '' $myGalleryName = '' $imageDefName = '' $Version = '1.0.0' # Azure region $location = 'uksouth' # Name of the image to be created $Date = Get-Date $imageTemplateName = "myWinImage_" + $date.ToShortDateString().Replace("/", "-") + "_" + $Date.ToShortTimeString().Replace(":", "-") # Distribution properties of the managed image upon completion $runOutputName = 'DistResults' # Your Azure Subscription ID $subscriptionID = (Get-AzContext).Subscription.Id # Get Identity $identityNameResourceId = (Get-AzUserAssignedIdentity -ResourceGroupName $imageResourceGroup -Name $identityName).Id #Gen 2 #VM Size $vmSize = "Standard_D2s_v4" # Image Template - Windows 11 AVD $srcObjParams = @{ SourceTypePlatformImage = $true Publisher = 'MicrosoftWindowsDesktop' Offer = 'Windows-11' Sku = 'win11-21h2-avd' Version = 'latest' } $srcObj = New-AzImageBuilderSourceObject @SrcObjParams # Distribution Settings $disObjParams = @{ SharedImageDistributor = $true ArtifactTag = @{tag = 'dis-share' } GalleryImageId = "/subscriptions/$subscriptionID/resourceGroups/$imageResourceGroup/providers/Microsoft.Compute/galleries/$myGalleryName/images/$imageDefName/Versions/$Version" ReplicationRegion = $location RunOutputName = $runOutputName ExcludeFromLatest = $false } $disObj = New-AzImageBuilderDistributorObject @disObjParams # Fix Sysprep $SysprepParams = @{ PowerShellCustomizer = $true CustomizerName = 'SysprepFix' RunElevated = $true runAsSystem = $true Inline = @("((Get-Content -path C:\DeprovisioningScript.ps1 -Raw) -replace 'Sysprep.exe /oobe /generalize /quiet /quit', 'Sysprep.exe /oobe /generalize /quit /mode:vm' ) | Set-Content -Path C:\DeprovisioningScript.ps1") } $CustomizerSysPrep = New-AzImageBuilderCustomizerObject @SysprepParams # Set array of Customerizers $customizers = $CustomizerSysprep, #Image Template Properties $ImgTemplateProperties = @{ Source = $srcObj Distribute = $disObj Customize = $customizers buildTimeoutInMinutes = 240 VMProfile = @{ VMProfileVmSize = $vmSize userAssignedIdentities = @( $identityNameResourceId ) } } # Image Template Parameters $ImgTemplateParams = @{ type = "Microsoft.VirtualMachineImages/imageTemplates" apiVersion = "2021-10-01" Properties = $ImgTemplateProperties Location = $location Identity = @{ type = "UserAssigned" userAssignedIdentities = @{ $identityNameResourceId = @{} } } } # Remove Plan information $content = $ImgTemplateParams | ConvertTo-Json -Depth 16 $content = $content -replace '"PlanInfoPlanName":.*,', '' $content = $content -replace '"PlanInfoPlanProduct":.*,', '' $content = $content -replace '"PlanInfoPlanPublisher":.*,', '' $content | Out-File .\Template.json -Force # Build Template New-AzImageBuilderTemplate -ImageTemplateName $imageTemplateName -ResourceGroupName $imageResourceGroup -JsonTemplatePath .\Template.json Remove-Item .\Template.json -Force # Build Image from Template Start-AzImageBuilderTemplate -ResourceGroupName $imageResourceGroup -Name $imageTemplateName -NoWait
7.2.4
0.2.0
No response
Thank you for your feedback. This has been routed to the support team for assistance.
Description
Deploying a new Image Builder template via PowerShell doesn't allow the addition of userAssignedIdentities to the VM. the option is in the json template, but gets removed when its deserialized. The same template works as expected via the Azure CLI.
Issue script & Debug output
Environment data
Module versions
Error output
No response