从下面的代码开始,我试图将安全组$ nsg添加到网络接口(interface)$ interface
$ interface.NetworkSecurityGroup的当前值为null

已经创建了安全组和newtork接口(interface)。如何将安全组分配给网络接口(interface)?

$resourceGroupName = "evoeitrg"
$interfaceName = "evoeitinterface"
$securityGroupName = "NsgWebServer"

$interface = Get-AzureRmNetworkInterface -Name $interfaceName -ResourceGroupName $resourceGroupName
$nsg = Get-AzureRmNetworkSecurityGroup -ResourceGroupName $resourceGroupName -Name $securityGroupName

最佳答案

这似乎是您要寻找的

$sg = Get-AzureRmNetworkSecurityGroup
$nic1 = New-AzureRmNetworkInterface -Name testnic `
                     -ResourceGroupName $rg `
                     -Location westeurope `
                     -SubnetId $subnetid
$nic1.NetworkSecurityGroup = $sg[1]
$nic1 | Set-AzureRmNetworkInterface

10-08 16:18