Azure / AzLoadBalancerMigration

This repo contains a PowerShell module to support Azure Load Balancer migration from Basic to Standard SKU
MIT License
10 stars 9 forks source link

Upgrade fails when VMSS extensions are present. #47

Closed dnapoleon closed 1 year ago

dnapoleon commented 1 year ago

When attempting to migrate a VMSS with extensions present in the Extensions Profile of the VMSS (such as Service Fabric Node), the Json Serializer fails to serialize the extensions as they are a type of "system.object".

log : 2023-04-24T11:24:11-04 [Error]:[BackupVmss] An error occured while exporting the VMSS '' for backup purposes. Error: Exception calling "Serialize" with "3" argument(s): "The collection type 'System.Object' on 'Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSetExtension.Settings' is not supported." At C:\Program Files\WindowsPowerShell\Modules\AzureBasicLoadBalancerUpgrade\2.0.4\modules\BackupBasicLoadBalancer\BackupBasicLoadBalancer.psm1:119 char:13

I manually copied the lines out of the BackupBasicLoadBalancer.psm1 file to test the serialization manually without the extensions and was able to serialize the rest of the VMSS.

  1. $vmss = Get-AzVmss -ResourceGroupName -VMScaleSetName
  2. $options = [System.Text.Json.JsonSerializerOptions]::new()
  3. $options.WriteIndented = $true
  4. $options.IgnoreReadOnlyProperties = $true
  5. $vmss.VirtualMachineProfile.ExtensionProfile.Extensions = $null
  6. [System.Text.Json.JsonSerializer]::Serialize($vmss, [Microsoft.Azure.Commands.Compute.Automation.Models.PSVirtualMachineScaleSet], $options)

The Service Fabric Node Extension snippet copied from Resource Explorer (resources.azure.com): { "name": "ServiceFabricNode", "properties": { "autoUpgradeMinorVersion": true, "publisher": "Microsoft.Azure.ServiceFabric", "type": "ServiceFabricNode", "typeHandlerVersion": "1.1", "settings": { "clusterEndpoint": "https://eastus.servicefabric.azure.com/runtime/clusters/my-guid", "nodeTypeRef": "primary", "dataPath": "D:\\SvcFab", "durabilityLevel": "Bronze", "enableParallelJobs": true, "nicPrefixOverride": "10.0.2.0/24", "certificate": { "thumbprint": "my cert thumbprint", "x509StoreName": "My" } } } }

mbrat2005 commented 1 year ago

@dnapoleon - Can you please confirm the version of PowerShell you are running this in by taking a look at the $PSVersionTable variable? If you are not using PowerShell Core, recommend giving that a try since we've had issue with the serialization portion running in PowerShell 5.1/Desktop.

dnapoleon commented 1 year ago

PS C:\WINDOWS\system32> $PSVersionTable

Name Value


PSVersion 5.1.22621.963
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.963
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

dnapoleon commented 1 year ago

I'll give PS Core a go.

dnapoleon commented 1 year ago

Matthew, thank you for such a quick response. This has addressed the issue.