The value of parameter imageReference.sku is invalid while creating the VM using Azure PowerShell

krishna572 886 Reputation points
2023-02-02T16:39:32.9266667+00:00

I'm trying to create a Windows 2016 Datacenter Virtual Machine using Azure PowerShell.

  1. Created the Resource Group
  2. Created the Storage Account
  3. Location is Central India
  4. Created the VNet, Subnet
  5. Created NSG Rule with NSG Group
  6. Created Public IP, VM Network Interface, VM Source Image, VM OS Disk.

Finally While creating the Virtual Machine , getting the below error. Could anyone help me where I'm doing wrong or missed any.

$vmName = "HariWinVM01"

$pubName = "MicrosoftWindowsServer"

$offerName = "WindowsServer"

$skuName = "2016-Datacenter "

$vmSize = "Standard_B2ms"

$vmConfig = New-AzVMConfig -VMName $vmName -VMSize $vmSize

New-AzVM -ResourceGroupName $ResourceGroup -Location $location -VM $vmConfig

WARNING: Since the VM is created using premium storage or managed disk, existing standard storage account, labstorageacc01, is used for boot diagnostics.
New-AzVM : The value of parameter imageReference.sku is invalid.
ErrorCode: InvalidParameter
ErrorMessage: The value of parameter imageReference.sku is invalid.
ErrorTarget: imageReference.sku
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : d20757c1-29a3-4bab-8480-d36d4140d9ca
At line:1 char:1
+ New-AzVM -ResourceGroupName $ResourceGroup -Location $location -VM $v ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzVM], ComputeCloudException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. Limitless Technology 44,746 Reputation points
    2023-02-03T17:15:27.4366667+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query.

    Here is a sample script to create a Windows Server 2016 Datacenter virtual machine in Azure using PowerShell:

    Import the AzureRM module

    Import-Module AzureRM

    Connect to Azure

    Connect-AzureRmAccount

    Select the Azure subscription you want to use

    Select-AzureRmSubscription -SubscriptionId "your-subscription-id"

    Set the resource group name

    $resourceGroupName = "your-resource-group-name"

    Create a new resource group

    New-AzureRmResourceGroup -Name $resourceGroupName -Location "West US"

    Set the virtual machine name

    $vmName = "your-virtual-machine-name"

    Set the admin username and password

    $adminUsername = "your-admin-username"

    $adminPassword = "your-admin-password" | ConvertTo-SecureString -AsPlainText -Force

    Create a new virtual machine configuration

    $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize "Standard_DS1_v2"

    $vm = Add-AzureRmVMOSDisk -VM $vmConfig -Name $vmName -Windows -CreateOption FromImage -StorageAccountType Standard_LRS -DiskSizeInGB 128 -ImageName "Win2016Datacenter"

    $vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential (New-Object PSCredential -ArgumentList $adminUsername, $adminPassword)

    $vm = Add-AzureRmVMNetworkInterface -VM $vm -Name "your-network-interface-name" -ResourceGroupName $resourceGroupName

    Create the virtual machine

    New-AzureRmVM -ResourceGroupName $resourceGroupName -Location "West US" -VM $vm

    Note: Replace your-subscription-id, your-resource-group-name, your-virtual-machine-name, your-admin-username, and your-admin-password with the appropriate values. Additionally, you may need to change the -Location and -VMSize to match your desired configuration.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Ewerton Jordão 5 Reputation points
    2023-02-02T17:52:39.2133333+00:00

    One typo in $skuName = "2016-Datacenter "

    remove space affter Datacenter.

    Try to use some commands to avoid typos:

    • Get-AzVMImagePublisher
    • Get-AzVMImageOffer
    • Get-AzVMImageSku
    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 44,746 Reputation points
    2023-02-03T17:16:26.52+00:00

    Double post

    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.