0
votes

When I'm trying to deploy an Azure Storage resource from azure automation runbook Here is my azure run book code

param (
    [Parameter(Mandatory=$true)]
    [string]
    $ResourceGroupName,

    [Parameter(Mandatory=$true)]
    [string]
    $StorageAccountName,

    [Parameter(Mandatory=$true)]
    [string]
    $StorageAccountKey,

    [Parameter(Mandatory=$true)]
    [string]
    $StorageFileName
)



# Authenticate to Azure if running from Azure Automation
$ServicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
Connect-AzureRmAccount `
    -ServicePrincipal `
    -TenantId $ServicePrincipalConnection.TenantId `
    -ApplicationId $ServicePrincipalConnection.ApplicationId `
    -CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint | Write-Verbose

#Set the parameter values for the Resource Manager template
$Parameters = @{
    "storageAccountType"="Standard_GRS"
    }

# Create a new context
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey

Get-AzureStorageFileContent -ShareName 'resource-templates' -Context $Context -path 'blobStorageOutput.json' -Destination 'C:\Temp'

$TemplateFile = Join-Path -Path 'C:\Temp' -ChildPath $StorageFileName

# Deploy the storage account
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $TemplateFile -TemplateParameterObject $Parameters

I'm getting the following two kinds of error error1:

Get-AzureStorageFileContent : The remote server returned an error: (400) Bad Request. HTTP Status Code: 400 - HTTP Error Message: One of the request inputs is out of range. At line:37 char:1 + Get-AzureStorageFileContent -ShareName 'resource-templates' -Context ... +

+ CategoryInfo : CloseError: (:) [Get-AzureStorageFileContent], StorageException + FullyQualifiedErrorId :
StorageException,Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet.GetAzureStorageFileContent

error 2:

New-AzureRmResourceGroupDeployment : Could not find file 'C:\Temp\blobStorageOutput.json'. At line:42 char:1 + New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupN ... +

+ CategoryInfo : CloseError: (:) [New-AzureRmResourceGroupDeployment], FileNotFoundException + FullyQualifiedErrorId :
Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

Here is my template for the azure storage:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {storageAccountType
      "": {
        "type": "string",
        "defaultValue": "Standard_ZRS",
        "allowedValues": [
          "Standard_LRS",
          "Standard_GRS",
          "Standard_ZRS",
          "Premium_LRS"
        ],
        "metadata": {
          "description": "Storage Account type"
        }
      },
      "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
          "description": "Location for all resources."
        }
      }
    },
    "variables": {
      "storageAccountName": "[concat('store', uniquestring(resourceGroup().id))]"
    },
    "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[variables('storageAccountName')]",
        "location": "[parameters('location')]",
        "apiVersion": "2018-07-01",
        "sku": {
          "name": "[parameters('storageAccountType')]"
        },
        "kind": "StorageV2",
        "properties": {}
      }
    ],
    "outputs": {
      "storageAccountName": {
        "type": "string",
        "value": "[variables('storageAccountName')]"
      },
      "storageUri":{
          "type": "string",
          "value": "[reference(variables('storageAccountName')).primaryEndPoints.Blob]"

      }
    }
  }

How can I resolve this issue Thanks in advance

1
Could you also post your template here?Joy Wang-MSFT
@JoyWang now you can see the updated question.saran k

1 Answers

1
votes

I can reproduce your issue on my side, make sure your $StorageAccountName is lowercase. For example, in my screenshot, it should be joystoragev2, not Joystoragev2. Also make sure other parameters are all correct.

enter image description here

The second error looks was caused by the failure of the Get-AzureStorageFileContent, if fix the first error, it should also work.