Reputation: 57
Getting error on removing vmss Network InterfaceConfiguration. Here is the code:
$myVmss = Get-AzVmss -ResourceGroupName 'MyApp-test-rg' -VMScaleSetName 'Myapp-vmss'
Remove-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $myVmss -Name $myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.IPConfigurations.Name
Getting error as-
Remove-AzVmssNetworkInterfaceConfiguration: Sequence contains no matching element
can someone please suggest.
EDITED:
all I am trying to do is to apply the backendpool config of basic LB to new standard LB. After following the suggestion of Joy, remove command worked but now facing issue on update-azvmss command.
$myVmss = Get-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName
$newlb = (Get-AzLoadBalancer -ResourceGroupName $rgName -Name $newLbName)
$mySubnetId = $myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.IpConfigurations[0].Subnet.Id
$backendPoolId = $newlb.BackendAddressPools.Id
$ipConfig = New-AzVmssIpConfig -Name MyNewConfig -SubnetId $mySubnetId -LoadBalancerBackendAddressPoolsId $backendPoolId
Remove-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $myVmss -Name $myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Name[1]
Add-AzVmssNetworkInterfaceConfiguration -Name MyNewConfig -Primary $true -VirtualMachineScaleSet $myVmss -IpConfiguration $ipConfig
$myVmss | Update-AzVmss
here is the error-
Update-AzVmss: Primary network interface configuration of VM scale set /subscriptions/xxxxxxxxxxxx/resourceGroups/xxxxxx-RG/providers/Microsoft.Compute/virtualMachineScaleSets/xxxxxxx cannot be changed. Original Primary network interface configuration: xxxxxx-vnet-v2-nic01, Requested: MyNewConfig.
Upvotes: 0
Views: 1420
Reputation: 42043
You need to pass the name of NetworkInterfaceConfiguration
, not IPConfiguration
, and you should note myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Name
is an array, so you need to give the specific one.
Before running Remove-AzVmssNetworkInterfaceConfiguration
, you may need to check $myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Name
to confirm the NetworkInterfaceConfiguration
you want to remove.
For example, you want to remove Test
, then the command should be:
Remove-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $myVmss -Name $myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Name[1]
Just a tip:
To make it take effect, you need to stop the VMSS, then use Update-AzVmss
after Remove-AzVmssNetworkInterfaceConfiguration
.
$myVmss = Get-AzVmss -ResourceGroupName testvmss -VMScaleSetName myvmss
Remove-AzVmssNetworkInterfaceConfiguration -VirtualMachineScaleSet $myVmss -Name $myVmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Name[1]
$myvmss | Update-AzVmss
Upvotes: 2