Search code examples
powershellazureazure-powershellpowershell-cmdlet

Azure New-AzureRmResource "Account Type" missing, but if I add it "Parameter not found"


I am trying to use New-AzureRmResource to create a new storage account. But I am running into something that is baffling me. My command is here:

New-AzureRmResource -Location "East US" -ResourceGroupName "myResGrp" -ResourceName "storagename" -ResourceType "microsoft.storage/storageaccounts" -Kind "Storage"

But this dumps the error

New-AzureRmResource : AccountTypeMissing : The accountType field is missing from the request.

So I add it in (tried both "AccountType" and "accountType"):

New-AzureRmResource -Location "East US" -ResourceGroupName "myResGrp" -ResourceName "storagename" -ResourceType "microsoft.storage/storageaccounts" -Kind "Storage" -AccountType "Standard_RAGRS"

Then I get the error:

New-AzureRmResource : A parameter cannot be found that matches parameter name 'AccountType'.

How do I pass this in? I assume I am missing something easy here. Thank you.

Answer thanks to the help below

$props = New-Object PSObject

$props | add-member AccountType "Standard_RAGRS"

$props | add-member Kind "Storage"

New-AzureRmResource -Location "East US" -ResourceGroupName "myResGrp" -ResourceName "storagename" -ResourceType "microsoft.storage/storageaccounts" -Properties $props -ApiVersion "2015-06-15"


Solution

  • You should put the accountType into a hash table for parameter "Properties" (if you are using 1.5.0, this is "PropertyObject"), and you should specify API version too. Here is an Example.

    $properties = @{"AccountType"="Standard_RAGRS"}
    
    New-AzureRmResource -Location "East US" `
                        -ResourceGroupName "myResGrp" `
                        -ResourceName "storagename" `
                        -ResourceType "Microsoft.Storage/storageAccounts" `
                        -Properties $properties `
                        -ApiVersion "2015-06-15"
    

    You need to specify API version because in the latest Azure PowerShell, by default, they are using 2016-03-30 for Storage Account, which has already changed AccountType to SKU, but the command New-AzureRmResource does not support SKU yet.