无法使用带有 Azure 自动化帐户的 azure 资源管理器模板部署 azure 存储

cannot deploy azure storage using azure resource manager template with Azure Automation Account

当我尝试从 Azure 自动化部署 Azure 存储资源时 运行book 这是我的 azure 运行 图书代码

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

我遇到以下两种错误 错误 1:

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

错误 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

这是我的 Azure 存储模板:

{
    "$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]"

      }
    }
  }

我该如何解决这个问题 提前致谢

我可以在我这边重现你的问题,确保你的 $StorageAccountName 是小写的。比如我的截图,应该是joystoragev2,而不是Joystoragev2。还要确保其他参数都正确。

第二个错误看起来是Get-AzureStorageFileContent失败引起的,如果修复第一个错误,它应该也可以。