简体   繁体   English

如何在没有 NSG 的情况下创建 Azure VM?

[英]How to create Azure VM without NSG?

I want to create a VM without nsg.我想创建一个没有 nsg 的 VM。 In the New-AzVm cmdlet, I specify $null in the PublicIP parameter - and it works (ie it does not create a Public IP).在 New-AzVm cmdlet 中,我在 PublicIP 参数中指定了 $null - 它可以工作(即它不会创建公共 IP)。 But this does not work with nsg.但这不适用于 nsg。 Here is my code:这是我的代码:

$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 

First of all, you should know, that it is highly not recommended using no NSG.首先,您应该知道,强烈建议不要不使用 NSG。 But if you need to do so, the only way to do it with Azure Powershell is (like @SaiSakethDuduru already said) with -nsg "".但是,如果您需要这样做,使用 Azure Powershell 的唯一方法是(就像@SaiSakethDuduru 已经说过的那样)使用 -nsg ""。 So need to use the stop-parsing affects variables.所以需要使用停止解析影响变量。

For additional information on parsing take a look in here: MS DOC about Parsing有关解析的更多信息,请查看此处: MS DOC about Parsing

When we use new-azvm cmdlet it don't work create VM without NSG.当我们使用 new-azvm cmdlet 时,它无法在没有 NSG 的情况下创建 VM。 Only Azure CLI can do it.只有 Azure CLI 可以做到。

az vm create --nsg '""'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM