我正在尝试使用 Powershell 的 AzureRm cmdlet 在 Azure 虚拟机规模集上的网络适配器上添加第二个 IP 地址。
我的代码如下所示:
Add-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId "XXXXXXXXXXXXXXXXXXXXXX"
$vnetname = "confvnet"
$loc = "West Europe"
$backendSubnetName = "conf-jira-interlink"
$backendSubnetConfig = New-AzureRmVirtualNetworkSubnetConfig -Name $backendSubnetName -AddressPrefix "10.0.4.0/24"
echo "backendSubnetConfig: "$backendSubnetConfig
$vnet = Get-AzureRmVirtualNetwork -Name $vnetname -ResourceGroupName "resourcegroup-confluence-jira-datacenter"
echo "vnet: "$vnet
Add-AzureRmVirtualNetworkSubnetConfig -Name $backendSubnetName -VirtualNetwork $vnet -AddressPrefix "10.0.4.0/24" | Set-AzureRmVirtualNetwork
$subnetId = (Get-AzureRmVirtualNetworkSubnetConfig -Name $backendSubnetName -VirtualNetwork $vnet).Id
echo "subnetId: "$subnetId
$ipCfg = New-AzureRmVmssIPConfig -Name 'eth1' -SubnetId $subnetId -PrivateIPAddressVersion 'IPv4' -Primary $false
echo "ipCfg: "$ipCfg
$backendSubnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $backendSubnetName -VirtualNetwork $vnet
echo "backendSubnet: "$backendSubnet
$vmss = Get-AzureRmVmss -ResourceGroupName resourcegroup-confluence-jira-datacenter -VMScaleSetName confcluster
echo "vmss: "$vmss
Add-AzureRmVmssNetworkInterfaceConfiguration -Name $backendSubnet -Primary $false -IPConfiguration $ipCfg -VirtualMachineScaleSet $vmss
$vmss = Get-AzureRmVmss -ResourceGroupName resourcegroup-confluence-jira-datacenter -VMScaleSetName confcluster
$Nic = Get-AzureRmNetworkInterface -ResourceGroupName "resourcegroup-confluence-jira-datacenter" -VirtualMachineScaleSetName 'confcluster'
echo "Nic: "$Nic
$ipconfig_interlink = New-AzureRmNetworkInterfaceIpConfig -Name "ipconfig-conf-jira-interlink" -Subnet $backendSubnetConfig -PrivateIpAddress "10.0.4.20"
Add-AzureRmNetworkInterfaceIpConfig -Name $ipconfig_interlink.Name -Subnet $backendSubnetConfig -NetworkInterface $Nic
Set-AzureRmNetworkInterfaceIpConfig -Name $ipconfig_interlink.Name -PrivateIpAddress 10.0.4.20 -Subnet $backendSubnetConfig -NetworkInterface $Nic
$Nic = Get-AzureRmNetworkInterface -ResourceGroupName "resourcegroup-confluence-jira-datacenter" -VirtualMachineScaleSetName 'confcluster'
echo "Nic: "$Nic
Set-AzureRmNetworkInterface -NetworkInterface $Nic
Update-AzureRmVmss -ResourceGroupName "resourcegroup-confluence-jira-datacenter" -VMScaleSetName "confcluster" -VirtualMachineScaleSet $vmss
但我得到了错误
Set-AzureRmNetworkInterface : 在 X:\JIRA_Confluence_Migration\PowerShell\network-interfaces-azure-same-vnet.ps1:67 Zeichen:1 + Set-AzureRmNetworkInterface -NetworkInterface $Nic + 中找不到资源'{0}' ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Set-AzureRmNetworkInterface],ArgumentException + FullyQualifiedErrorId:Microsoft.Azure.Commands.Network.SetAzureNetworkInterfaceCommand 在 Set-AzureRmNetworkInterface。
有谁知道问题是什么?