Create VM with Get-AzVM on playground azure

Hi ,
I’m doing AZ-Course and I try to use script provided , but I have problem to create VM as unable to use the right image with the right SKU for the disk (as policy don’t let premium disk to be created) , please may you give me the right command : below a part of the script (from git AZ104\v2\050- Administer Virtual Networking)
New-AzVM -Name “workload-a-vm-$i” -ResourceGroupName $rg
-Location eastus -Size 'Standard_B1s'
-Image “Ubuntu2204” -VirtualNetworkName "vnet-workloads"
-SubnetName ‘snet-workload-a’ -Credential $credential
-PublicIpAddressName “workload-a-vm-$i-pip” `
-PublicIpSku Standard

Could you link please to the lab you’re working on? A bit of context would help us help you.

Hi Rob

I’m working on lab AZ104 and I’m on the part of NSG course . to follow it I use github : AZ104/v2/050- Administer Virtual Networking at main · kodekloudhub/AZ104 · GitHub . I 'm looking for a way to create VM with standard LRS instead of premium LRS which is not allowed with the policy of the playground azure kodekloud.

Thx for your help

Still need more information; I’m asking my colleagues to look into this, but we’ll need more from you. Please:

  • Give a link to an actual lab, so we know why you’re running the script and in what context; the repo does not tell me why you’re running this script.
  • Give us more information about what error you’re getting – a screen shot would be very useful here.

Hi

I cannot attached file.
So :

all informations : script used : nsg-prep-infra.ps1
in AZ104/v2/050- Administer Virtual Networking at main · kodekloudhub/AZ104 · GitHub

I modify resource group to take account of the one in the playground azure

*Error is : *
Line |

  • 43 | $spAvm = New-AzVM -Name “workload-a-vm-$i” `*
  • |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
    
  • | Long running operation failed with status 'Failed'. Additional Info:'Resource 'workload-a-vm-2_OsDisk_1_a88bc343fa5d4ef985325b8934b9d981' was disallowed by policy. Reasons: 'This storage configuration is not  *
    
  • | allowed. Ensure the disk size is 128 GB or less and the SKU is not Premium for Compute disks. For Storage accounts, use Standard_LRS or Standard_RAGRS SKUs.'. See error details for policy resource IDs.        *
    
  • | Target: '/subscriptions/a2b28c85-1948-4263-90ca-bade2bac4df4/resourceGroups/kml_rg_main-0dcc7f44613e4e06/providers/Microsoft.Compute/disks/workload-a-vm-2_OsDisk_1_a88bc343fa5d4ef985325b8934b9d981'.'*
    

I asked our engineers about this. One of them made the following suggestion:

# Preferences

$ErrorActionPreference = "SilentlyContinue"



# Variables

$rg = (az group list --query '[0].name' -o tsv) # Get the first resource group name

$region = "eastus"

$username = "kodekloud" 

$plainPassword = "VMP@55w0rd2023!" 



# Create virtual network and subnets

Write-Host "Adding workload-a network configuration"



az network vnet create --resource-group $rg --name vnet-workloads --address-prefix 192.168.0.0/16 --location $region | Out-Null

az network vnet subnet create --resource-group $rg --vnet-name vnet-workloads --name snet-workload-a --address-prefix 192.168.1.0/24 | Out-Null

az network vnet subnet create --resource-group $rg --vnet-name vnet-workloads --name snet-workload-b --address-prefix 192.168.2.0/24 | Out-Null



# Function to create VM

function Create-VM {

    param (

        [string]$VMName,

        [string]$SubnetName

    )



    Write-Host "Creating $VMName"



    # Create public IP

    az network public-ip create --resource-group $rg --name "$VMName-pip" --sku Standard --location $region | Out-Null



    # Create network interface

    az network nic create --resource-group $rg --name "$VMName-nic" --vnet-name vnet-workloads --subnet $SubnetName --public-ip-address "$VMName-pip" --location $region | Out-Null



    # Create VM

    az vm create `
        --resource-group $rg `
        --name $VMName `
        --location $region `
        --nics "$VMName-nic" `
        --image "Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:latest" `
        --size Standard_B1s `
        --admin-username $username `
        --admin-password $plainPassword `
        --os-disk-size-gb 128 `
        --storage-sku Standard_LRS `
        --no-wait | Out-Null


    Write-Host "$VMName creation initiated"

}



# Create VMs in the subnets

for ($i = 1; $i -lt 3; $i++) {

    Create-VM -VMName "workload-a-vm-$i" -SubnetName "snet-workload-a"

    Create-VM -VMName "workload-b-vm-$i" -SubnetName "snet-workload-b"

}

Hi Rob,

thanx to you and to your colleagues. It 's working fine with this scripts.

Regards