Azure-cli: Can't create VM without a public IP address

Created on 18 Jan 2019  Â·  15Comments  Â·  Source: Azure/azure-cli

Sample code "az vm create -n MyVm -g MyResourceGroup --public-ip-address "" --image Win2012R2Datacenter" throws an error

az vm create: error: argument --public-ip-address: expected one argument

How do I create a VM without a public IP address?

Here is info on my az cli version

az --version
azure-cli (2.0.49)

acr (2.1.7)
acs (2.3.9)
advisor (0.6.0)
ams (0.2.4)
appservice (0.2.5)
backup (1.2.1)
batch (3.4.1)
batchai (0.4.4)
billing (0.2.0)
botservice (0.1.1)
cdn (0.2.0)
cloud (2.1.0)
cognitiveservices (0.2.3)
command-modules-nspkg (2.0.2)
configure (2.0.18)
consumption (0.4.0)
container (0.3.7)
core (2.0.49)
cosmosdb (0.2.2)
dla (0.2.3)
dls (0.1.4)
dms (0.1.1)
eventgrid (0.2.0)
eventhubs (0.3.0)
extension (0.2.2)
feedback (2.1.4)
find (0.2.12)
hdinsight (0.1.0)
interactive (0.3.31)
iot (0.3.3)
iotcentral (0.1.3)
keyvault (2.2.5)
lab (0.1.2)
maps (0.3.2)
monitor (0.2.5)
network (2.2.7)
nspkg (3.0.3)
policyinsights (0.1.0)
profile (2.1.1)
rdbms (0.3.2)
redis (0.3.2)
relay (0.1.2)
reservations (0.4.0)
resource (2.1.5)
role (2.1.8)
search (0.1.1)
servicebus (0.3.1)
servicefabric (0.1.6)
signalr (1.0.0)
sql (2.1.5)
storage (2.2.3)
telemetry (1.0.0)
vm (2.2.6)

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\Max.azurecliextensions'

Python (Windows) 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Compute-cli question

Most helpful comment

@tjprescott - why was this issue closed?

All 15 comments

Upgrading to azure-cli (2.0.55) did not help. :(

What shell environment are you using?

PowerShell on Windows 10

btw, i just commented on a similar issue (https://github.com/Azure/azure-cli/issues/3917) that you have closed. I don't understand why the same az cli command would work in Windows Command Line, but fail in Windows PowerShell.

They are all different shell enviroments and process things differently. The shell-specific processing occurs before the data ever reaches the CLI, so there is no way to have a single syntax that will work between bash, CMD.exe and Powershell. In this case, Powershell eats the empty string as if it weren't sent, resulting in the error you see.

The syntax that will work in your case (and any other cases where the argument can take empty string) is:
--public-ip-address '""'

--public-ip-address '""' worked. thanks.

But for New-AzVM PowerShell cmdlet this hack doesn't work. We need the proper self-explanatory option such as --withoutPublicIpAddress, not be resorted to using obscure feature with semantic from 1980s.

I have the same issue. Been fighting it for a few hours with new-azvm and can't figure out how create a VM without public IP.

This is what it looks like in powershell

New-AzVm `
>>     -ResourceGroupName $resourceGroupName `
>>     -Name "av-vm-no-pubip2" `
>>             <#-Name "av-vm-$(get-random)" #>`
>>     -Location $location `
>>     -Credential $SecureCredentialObject `
>>     -Image "MicrosoftWindowsServer:WindowsServer:2016-Datacenter-with-Containers:latest" `
>>     -Size "Standard_D1" `
>>     -VirtualNetworkName $vnet.name `
>>     -SubnetName $subnet2.Name `
>>     -PublicIpAddressName <Magic here>

I tried whatever I could think of: $null, "", '""' '""', '""'. none of these work.

I'm also having this issue. @tjprescott. Do you have a way to create a VM without a public IP using the New-AzVm powershell module?

I'm having this issue too.

I was able to use New-AzVm to create a VM without a public IP address. I'm afraid I can't take the credit for the below. It's from PS help files. I had to adapt it to be able to create a new VM in an existing network and subnet and apply an existing NSG but the below will create a new VM without a public IP using the PS New-AzVm cmdlet. I'd tried lots of things like null and two sets of quotes all to no avail. I hope this helps some people.

$VMLocalAdminUser = "LocalAdminUser"
$VMLocalAdminSecurePassword = ConvertTo-SecureString <password> -AsPlainText -Force
$LocationName = "westus"
$ResourceGroupName = "MyResourceGroup"
$ComputerName = "MyVM"
$VMName = "MyVM"
$VMSize = "Standard_DS3"

$NetworkName = "MyNet"
$NICName = "MyNIC"
$SubnetName = "MySubnet"
$SubnetAddressPrefix = "10.0.0.0/24"
$VnetAddressPrefix = "10.0.0.0/16"

$SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix
$Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroupName -Location $LocationName -AddressPrefix 
$VnetAddressPrefix -Subnet $SingleSubnet
$NIC = New-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroupName -Location $LocationName -SubnetId $Vnet.Subnets[0].Id

$Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword);

$VirtualMachine = New-AzVMConfig -VMName $VMName -VMSize $VMSize
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent 
-EnableAutoUpdate
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName 'MicrosoftWindowsServer' -Offer 'WindowsServer' -Skus 
'2012-R2-Datacenter' -Version latest

New-AzVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $VirtualMachine -Verbose

This example provisions a new network and deploys a Windows VM from the Marketplace without creating a public IP address or Network Security 
Group. This script can be used for automatic provisioning because it uses the local virtual machine admin credentials inline instead of 
calling Get-Credential which requires user interaction.

I am trying to deploy a VM from a generalized Private Image into and existing Vnet and Subnet but cannot do it without an NSG being created. Attempting to use "" for the NSG and PIP simply cause the process to bomb, since it is expecting a pre-existing NSG to exist.

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-generalized-managed

The above MSFT example, does not appear to allow you to specify a private image. It seems insane that I need to provision a NSG and PIP via automation on the machine, then run another 2 lines to delete the NSG and PIP....

I would appreciate any help or other views on this or if there is a way to do this using AZ VM Create, I tried that first but couldn't find a way.

Thanks!

@tjprescott - why was this issue closed?

Was this page helpful?
0 / 5 - 0 ratings