How to create VM using powershell ?

akash yadav 20 Reputation points
2023-11-04T04:52:04.8566667+00:00

How to create VM using powershell as i am new to azure cloud ?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
6,318 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vikas Singh 145 Reputation points
    2023-11-04T04:58:05.1033333+00:00

    You can create vm under resource group using below command-

    1. Create resource group-

    New-AzResourceGroup -Name 'myResourceGroup' -Location 'EastUS'

    1. Create virtual machine-

    you can also check msdn link- https://learn.microsoft.com/en-us/azure/virtual-machines/windows/quick-create-powershell

    New-AzVm `
        -ResourceGroupName 'myResourceGroup' `
        -Name 'myVM' `
        -Location 'East US' `
        -Image 'MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest' `
        -VirtualNetworkName 'myVnet' `
        -SubnetName 'mySubnet' `
        -SecurityGroupName 'myNetworkSecurityGroup' `
        -PublicIpAddressName 'myPublicIpAddress' `
        -OpenPorts 80,3389
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Dillon Silzer 49,166 Reputation points
    2023-11-04T21:58:46.8533333+00:00

    Hi Akash,

    Just to add to what Vikas mentioned (if you are new to Azure PowerShell) you will need to install the necessary module (run PowerShell as Administrator):

    Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
    

    You will also need to:

    Connect-AzAccount
    

    Then run

    New-AzVm `
        -ResourceGroupName 'myResourceGroup' `
        -Name 'myVM' `
        -Location 'East US' `
        -Image 'MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest' `
        -VirtualNetworkName 'myVnet' `
        -SubnetName 'mySubnet' `
        -SecurityGroupName 'myNetworkSecurityGroup' `
        -PublicIpAddressName 'myPublicIpAddress' `
        -OpenPorts 80,3389
    

    A larger guide:

    https://www.educative.io/answers/how-to-create-an-azure-resource-group-using-powershell


    If this is helpful please accept answer.

    0 comments No comments