1

I'm creating VM on Azure from an Image using powershell.

This is the script I'm using .

$UserName = "username"
$Password = ConvertTo-SecureString "password@123" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)    
New-AzureRmVm `
    -ResourceGroupName "RSG" `
    -Name "VMName" `
    -ImageName "ImageName" `
    -Location "West US" `
    -VirtualNetworkName "VNName" `
    -SubnetName "default" `
    -Credential $psCred
    -PublicIpAddressName "None" `
    -OpenPorts 3389

But, when I got into the Azure portal and see, some Public Ip is getting assigned by default. I have also tried without giving PublicIpAddressName property assuming , it wont assign any IP, but still it is assigning.

I want the Public IP to be none.Can anyone help me achieve this.Thanks!

CrazyCoder
  • 2,194
  • 10
  • 44
  • 91

4 Answers4

1

Currently this an issue which is still in Open state on official azure-powershell github. You can refer it here . Incase if you still want to bypass this you can try using New-AzureReservedIP or after the deployment command try to remove the public ip by yourself Remove-AzureRmPublicIpAddress.

Note : I have'nt tested it yet. Just an idea.

Refer : Docs

HariHaran
  • 3,642
  • 2
  • 16
  • 33
0

To set no public ip address you have can just define it as "" , in powershell you will need to quote that again so it will be """" .

Amias
  • 335
  • 6
  • 16
  • 2
    This is not true. I have actually tried it (however stupidly this advice sounded), using `New-AzVM ... -PublicIpAddressName """" ...` and I've got the error: `New-AzVM : Resource name " is invalid. The name can be up to 80 characters long. It must begin with a word character, a nd it must end with a word character or with '_'. The name may contain word characters or '.', '-', '_'.` It also doesn't work when the name is specified as `'""'`. Maybe it works with `az` command, but not for PowerShell cmdlet. – Endrju Oct 04 '19 at 17:08
  • this was a bug that has probably been fixed then. – Amias Oct 07 '19 at 16:32
0

If you are using PowerShell, then you will need to escape all empty parameters by changing "" to '""' to properly pass an empty string into the command. Without this, PowerShell will not pass the empty string, and you will get an error from the command indicating it's missing a parameter.

-1
$winVmCred = Get-Credential `
  -Message "Enter username and password for the Windows management virtual machine."

# Create a NIC for the VM.
$winVmNic = New-AzNetworkInterface -Name "winVMNIC01" `
  -ResourceGroupName $resourceGroup.ResourceGroupName `
  -Location $location `
  -SubnetId $targetVMSubnet.Id `
  -PrivateIpAddress "10.10.12.10"

# Configure the Windows management VM.
$winVmConfig = New-AzVMConfig -VMName $winVmName -VMSize $winVmSize | `
Set-AzVMOperatingSystem -Windows -ComputerName $winVmName -Credential $winVmCred | `
Set-AzVMSourceImage -PublisherName $winVmPublisher `
  -Offer $winVmOffer `
  -Skus $winVmSku `
  -Version $winVmVersion | `
  Add-AzVMNetworkInterface -Id $winVmNic.Id

# Create the VM.
$winVM = New-AzVM -ResourceGroupName $resourceGroup.ResourceGroupName `
  -Location $location `
  -VM $winVmConfig `
  -ErrorAction Stop