2015-12-08 33 views
4

使用Azure CLI,可以創建公共ip地址並將其分配給現有網絡地址。使用powershell將公共ip地址分配給Azure中的現有網絡地址

創建一個給定的資源組一個公網IP和區域

azure network public-ip create -g myresourcegroup -a Dynamic -l westus mypublicipname 

在上一步中創建PIP分配給現有的NIC

azure network nic set -g myresourcegroup -p mypublicipname mynicname 

但是類似的代碼在PowerShell中沒有按沒有工作,例如

創建一個新的PIP(成功完成)

$pip = New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic -Force 

分配給現有的NIC

$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName 
$nic.IpConfigurations[0].PublicIpAddress = $pip.IpAddress 

最後行不工作,並引發以下錯誤:

The property 'Id' cannot be found on this object. Verify that the property exists and can be set. 
At line:31 char:9 
+   $nic.IpConfigurations[0].PublicIpAddress.Id = $pip.Id 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : PropertyNotFound 

儘管PS ISE中的intellisense確實顯示了兩者的Id屬性!有誰知道這是否應該工作?

回答

3

感謝AzureCAT的Tim Wieman(MSFT)提供的解決方案!基本上,您需要將新創建的點分配給nic的PublicIPAddress屬性,然後運行Set-AzureRmNetworkInterface命令,如下所示:

$nic.IpConfigurations[0].PublicIpAddress = $pip 
    Set-AzureRmNetworkInterface -NetworkInterface $nic