[英]Azure Powershell - Problem with assigning private IP address to an NIC
Here is my script这是我的脚本
$my_vnet = Get-AzVirtualNetwork -Name <vnet_name>
$my_subnet = Get-AzVirtualNetworkSubnetConfig -Name <subnet_name> -VirtualNetwork $my_vnet
Add-AzNetworkInterfaceIpConfig -Name ext-ipconfig6 -NetworkInterface $my_nic -
Subnet $my_subnet -PrivateIpAddress 10.0.0.6
There is no error when running the script.运行脚本时没有错误。 If I use the following command to check, I do see the IP object created.如果我使用以下命令进行检查,我确实看到创建了 IP object。
Get-AzNetworkInterfaceIpConfig -Name ext-ipconfig6 -NetworkInterface $my_nic
...
{
"Name": "ext-ipconfig6",
"PrivateIpAddress": "10.0.0.6",
"PrivateIpAllocationMethod": "Static",
"Subnet": {
"Id": "blabla"
},
"Primary": false
}
However, I don't see it created on the portal.但是,我没有看到它在门户网站上创建。
Comparing with others created in the portal, I see other properties like Etag
, Id
, ProvisioningState
, ...etc.与门户中创建的其他属性相比,我看到了其他属性,如Etag
、 Id
、 ProvisioningState
等。 Where did I do wrong...?我哪里做错了……? Thanks!谢谢!
You are just creating the Network Interface IP configuration and not setting it to the existing Network interface itself.您只是在创建网络接口 IP 配置,而不是将其设置为现有网络接口本身。
I tested the same script which resulted as below:我测试了相同的脚本,结果如下:
To fix the above you will have to add | Set-AzNetworkInterface
要解决上述问题,您必须添加| Set-AzNetworkInterface
| Set-AzNetworkInterface
after the Add-AzNetworkInterfaceIpConfig
command like below:在Add-AzNetworkInterfaceIpConfig
命令之后| Set-AzNetworkInterface
,如下所示:
$vnet = Get-AzVirtualNetwork -Name "ansuman-vnet" -ResourceGroupName "ansumantest"
$nic= Get-AzNetworkInterface -Name "ansumannic01" -ResourceGroupName "ansumantest"
Add-AzNetworkInterfaceIpConfig -Name "IPConfig2" -NetworkInterface $nic -Subnet $vnet.Subnets[0] -PrivateIpAddress "10.0.0.7" | Set-AzNetworkInterface
Output: Output:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.