无法通过Azure自动化帐户使用Azure资源管理器模板来部署Azure存储

时间:2019-09-17 07:14:04

标签: azure powershell azure-storage azure-resource-manager azure-automation

当我尝试从Azure自动运行手册部署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:远程服务器返回错误:   (400)错误的请求。 HTTP状态码:400-HTTP错误消息:   请求输入超出范围。在第37行:char:1 +   Get-AzureStorageFileContent -ShareName'资源模板'-上下文   ... +

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

错误2:

  

New-AzureRmResourceGroupDeployment:找不到文件   'C:\ Temp \ blobStorageOutput.json'。在第42行char:1 +   New-AzureRmResourceGroupDeployment -ResourceGroupName $ ResourceGroupN   ... +

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

这是我的天蓝色存储模板:

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

      }
    }
  }

如何解决此问题 预先感谢

1 个答案:

答案 0 :(得分:1)

我可以站在一边复制您的问题,请确保您的$StorageAccountName为小写。例如,在我的屏幕快照中,它应该是joystoragev2,而不是Joystoragev2。还要确保其他参数都正确。

enter image description here

第二个错误看上去是由Get-AzureStorageFileContent的故障引起的,如果解决了第一个错误,它也应该起作用。