簡體   English   中英

使用PowerShell為Azure中的現有nic分配公共IP地址

[英]Assigning a public ip address to an existing nic in Azure using powershell

使用Azure CLI,可以創建公共IP地址並為其分配例如

在給定的資源組和區域中創建公共IP

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

將上一步中創建的點數分配給現有的nic

azure network nic set -g myresourcegroup -p mypublicipname mynicname

但是,PowerShell中的類似代碼不起作用,例如

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

$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屬性! 有誰知道這是否應該有效?

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM