Cannot create VM via powershell using Azure Free account and services

Himanish Lekhi 20 Reputation points
2023-02-20T11:48:55.6166667+00:00

Hi there,

I am trying to create a VM via PowerShell and I am using Azure free services as I signed up with Azure to get some hands-on experience.

I can't create a VM as it is gives me an error every time, I create it using Australia Central location.

It asks me to enter a Name after a message of supply values for the following parameters.

Whatever I enter as the name, it selects that as resource group name and VM name and it changes the location to eastus.

Can someone please assist me and explain where the problem lies?

New-AzVM
    -ResourceGroupName $ResourceGroup
    -Name $VMName
    -Location $Location
    -VirtualNetworkName "az104vmpsVnet"
    -SubnetName "az104vmpsSubnet"
    -SecurityGroupName "az104vmpsNetworkSecurityGroup"
    -PublicIpAddressName "az104vmpsPublicIpAddress"
    -OpenPorts 3389
cmdlet New-AzVM at command pipeline position 1
Supply values for the following parameters:
Name: Mlb-VM01
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
0 comments No comments
{count} votes

Accepted answer
  1. TP 124.7K Reputation points Volunteer Moderator
    2023-02-20T14:13:47.25+00:00

    Hi,

    Did you set values for your variables ($ResourceGroup, $VMName, $Location) before trying to run New-AzVM? Below is a sample script to create VM in Australia Central:

    $ResourceGroup = "my-resource-group-rg"
    $VMName = "Mlb-VM01"
    $Location = "australiacentral"
    $cred = New-Object System.Management.Automation.PSCredential ("azureuser", (ConvertTo-SecureString "P@assw0rd!" -AsPlainText -Force))
    New-AzVM -ResourceGroupName $ResourceGroup -Name $VMName -Location $Location -VirtualNetworkName "az104vmpsVnet" -SubnetName "az104vmpsSubnet" -SecurityGroupName "az104vmpsNetworkSecurityGroup" -PublicIpAddressName "az104vmpsPublicIpAddress" -OpenPorts 3389 -Size "Standard_B2s" -Credential $cred
    
    

    The above will create the VM with Premium SSD for the OS disk. I recommend deleting the resource group immediately after you are done testing/learning for the day to minimize ongoing costs.

    Please click Accept Answer if the above was helpful.

    Thanks.

    -TP

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. vipullag-MSFT 26,487 Reputation points Moderator
    2023-02-21T03:11:54.3266667+00:00

    Hello Himanish Lekhi

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    Adding to the above response form TP, based on the output you provided looks like the PowerShell command is prompting you to enter a value for the "Name" parameter. This is expected behavior, as the command requires you to specify a name for the virtual machine.

    You entered "Mlb-VM01" as the name for the virtual machine. It's possible that the command is automatically using this same value as the name of the resource group, which is not what you intended.

    Make sure that you are specifying the correct location when you run the command. It's possible that the default location for your Azure subscription is set to eastus, which is why it keeps changing the location to that value.

    -Location "AustraliaCentral"

    Hope this helps.

    If the suggested response helped you resolve your issue, please 'Accept as answer', so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.