从下面的代码开始,我正在尝试将安全组$ nsg添加到网络接口$ interface $ interface.NetworkSecurityGroup的当前值为null
已经创建了安全组和newtork接口。如何将安全组分配给网络接口?
$resourceGroupName = "evoeitrg"
$interfaceName = "evoeitinterface"
$securityGroupName = "NsgWebServer"
$interface = Get-AzureRmNetworkInterface -Name $interfaceName -ResourceGroupName $resourceGroupName
$nsg = Get-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroupName -Name $securityGroupName
答案 0 :(得分:4)
这似乎是你正在寻找的
$sg = Get-AzureRmNetworkSecurityGroup
$nic1 = New-AzureRmNetworkInterface -Name testnic `
-ResourceGroupName $rg `
-Location westeurope `
-SubnetId $subnetid
$nic1.NetworkSecurityGroup = $sg[1]
$nic1 | Set-AzureRmNetworkInterface