如何在没有NSG的情况下创建Azure虚拟机



我想创建一个没有nsg的VM。在New-AzVm cmdlet中,我在PublicIP参数中指定$null,并且它有效(即它不创建公共IP(。但这对nsg不起作用。这是我的代码:

$Date = Get-Date -Format "MMddyymm"
$user = "Sitecore"
$password = ConvertTo-SecureString "Qwerty123456" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $password
$RGroup = 'test'
$Location = "Westus3"
$VMName = "vmtest$date"
$image = "vmtest-image-20220805165444"
$vnet = "vnet1"
$NSG = "nsg$date"
$SizeVM = "Standard_b4ms"
$NIC = "$VMName$date"
$Subnet = "default"
$tags = @{'xxx' = 'yyy'}
New-AzVM -ResourceGroupName $RGroup `
-Name $VMName `
-Image $image `
-Location $Location `
-VirtualNetworkName $vnet `
-SubnetName $Subnet `
-SecurityGroupName $null `
-PublicIpAddressName $null `
-Credential $credential `
-Size $SizeVM 

首先,您应该知道,强烈建议不要使用NSG。但如果你需要这样做,使用Azure Powershell的唯一方法是(就像@SaiSakethDuduru已经说过的那样(使用-nsg"&";。所以需要使用停止解析影响变量。

有关解析的其他信息,请查看此处:关于解析的MS DOC

当我们使用new-azvmcmdlet时,它不起作用。相反,创建一个没有NSG的虚拟机。只有Azure CLI才能做到这一点:

az vm create --nsg '""' 

相关内容

最新更新