2
votes

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"

2

2 Answers

4
votes

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.

1
votes

If you have AzureRM.Resources of version 2.0, it should support the latest properties you need to make this work. Prior to 2016-01-01 version of the api, SKU was called accountType, as the problem you're having.

https://msdn.microsoft.com/en-us/library/azure/mt712701.aspx

Check the module version you're running:

 Get-Module  AzureRM.Resources 

I'd recommend updating your AzureRM module, using Update-Module (assuming WMF5 installed and that you installed the AzureRM.Resources module in the firstplace using get-module/install-module).

If you cannot upgrade your AzureRM.Resources module; you can always specify the properties missing using -Properties @{ "AccountType"="Standard_RAGRS"}. You can also try using the New-AzureRmStorageAccount , it might have the properties you're looking for (as the cmdlet is under AzureRM.Storage, and could have a different version / subset).

Hope this helps!:)