Need powershell script to create Azure VM with standard OS Disk type .

Naveen Neerukattu 26 Reputation points

Hi Team,
I am trying to create Vm in Azure by using PowerShell script but it is failed to create Vm because by default it is taking OS Disk type as : Premium Disk 252273-image.png
But it want to create Vm with OS Disk type as Standad SSD .252332-image.png

$location = 'east us'
$cred = Get-Credential -Message "Enter user name and password"
New-Azvm -name vm1 -ResourceGroupName ODL-azure-769268 -Location $location -VirtualNetworkName vnet1 -SubnetName subnet1 -Credential $cred.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,373 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,430 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Manu Philip 17,021 Reputation points MVP

    I have prepared a PowerShell script as below:
    Disk type is Standard SSD LRS

    Change the following values as per your preference.

    • username
    • password
    • Resource Group Name (create the resource group before starting the script)

    The script is able to create a Windows 2019 Datacenter server and prepares a security group so that you can access the computer through RDP

    $vmAdminUsername = "Enter UserName"  
    $vmAdminPassword = ConvertTo-SecureString "Enter strong Password" -AsPlainText -Force  
    $vmComputerName = "WIN2K19"  
    $azureLocation  = "EastUS"  
    $azureResourceGroup = "Enter Resource Group Name"  
    $azureVmName  = "WIN2K19"  
    $azureVmSize  = "Standard_D2s_v3"  
    $azureVmPublisherName = "MicrosoftWindowsServer"  
    $azureVmOffer = "WindowsServer"  
    $azureVmSkus = "2019-Datacenter"  
    $NetworkName = "MyNet"  
    $NICName = "MyNIC"  
    $SubnetName = "MySubnet"  
    $azurePublicIpName = "MyPublicIP"  
    $SubnetAddressPrefix = ""  
    $VnetAddressPrefix = ""  
    $NSGName = "MyNSG"  
    $azurePublicIp = New-AzPublicIpAddress -Name $azurePublicIpName -ResourceGroupName $azureResourceGroup -Location $azureLocation -AllocationMethod Dynamic  
    $SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix  
    $Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $azureResourceGroup -Location $azureLocation -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet  
    $nsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name RDP  -Protocol Tcp  -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow;  
    $nsg = New-AzNetworkSecurityGroup -ResourceGroupName $azureResourceGroup -Location $azureLocation -Name $NSGName  -SecurityRules $nsgRuleRDP;  
    $NIC = New-AzNetworkInterface -Name $NICName -ResourceGroupName $azureResourceGroup -Location $azureLocation -SubnetId $Vnet.Subnets[0].Id -PublicIpAddressId $azurePublicIp.Id -NetworkSecurityGroupId $nsg.Id  
    $vmCredential = New-Object System.Management.Automation.PSCredential ($vmAdminUsername, $vmAdminPassword)  
    $VirtualMachine = New-AzVMConfig -VMName $azureVmName -VMSize $azureVmSize  
    $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $vmComputerName -Credential $vmCredential  
    $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id  
    $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName $azureVmPublisherName -Offer $azureVmOffer -Skus $azureVmSkus -Version "latest"  
    $VirtualMachine = Set-AzVMBootDiagnostic -VM $VirtualMachine -Disable  
    $VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -StorageAccountType "StandardSSD_LRS" -CreateOption FromImage  
    New-AzVM -ResourceGroupName $azureResourceGroup -Location $azureLocation -VM $VirtualMachine -Verbose  


    --please don't forget to upvote and Accept as answer if the reply is helpful--

    2 people found this answer helpful.
    0 comments No comments

  2. Naveen Neerukattu 26 Reputation points

    Can anyone help me to create Vm with powershell by making os disk type as standard SSD

  3. Limitless Technology 44,046 Reputation points


    Thank you for posting your query.

    Kindly follow the steps provided below to resolve your issue.

    The exercises in this tutorial require a VM. Follow the steps in this section to create one.

    Before you begin, find the $azRegion variable located in the first line of sample code and update the value to reflect your desired region. For example, to specify the Central US region, use $azRegion = "Central US". Next, use the code to deploy a VM within a new resource group. You're prompted for username and password values for the VM's local administrator account.

    $azRegion = "[Your Region]"
    $azResourceGroup = "myDemoResourceGroup"
    $azVMName = "myDemoVM"
    $azDataDiskName = "myDemoDataDisk"

    New-AzVm -Location $azRegion
    -ResourceGroupName $azResourceGroup -Name $azVMName
    -Size "Standard_D2s_v3" -VirtualNetworkName "myDemoVnet"
    -SubnetName "myDemoSubnet" -SecurityGroupName "myDemoNetworkSecurityGroup"
    -PublicIpAddressName "myDemoPublicIpAddress"

    Go to this link for your reference


    If the answer is helpful kindly click "Accept as Answer" and upvote it. Thanks.

    0 comments No comments