【问题标题】:How to create Azure VM without NSG?如何在没有 NSG 的情况下创建 Azure VM?
【发布时间】:2022-08-20 09:24:29
【问题描述】:

我想创建一个没有 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 
  • 你试过这个命令吗 az --% vm create --nsg \"\"

标签: azure powershell virtual-machine network-security-groups


【解决方案1】:

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

有关解析的更多信息,请查看此处: MS DOC about Parsing

【讨论】:

    【解决方案2】:

    当我们使用new-azvm cmdlet 时,它不起作用。相反,创建一个没有 NSG 的 VM。只有 Azure CLI 可以执行此操作:

    az vm create --nsg '""' 
    

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      相关资源
      最近更新 更多