【问题标题】:Enable-AzStorageStaticWebsite command in Azure RM PowerShell moduleAzure RM PowerShell 模块中的 Enable-AzStorageStaticWebsite 命令
【发布时间】:2018-12-17 16:37:12
【问题描述】:

我正在尝试创建一个自动化脚本来创建静态网站并将其部署到 Azure 存储 Blob。

但是,我仍然必须使用Azure.Storage 模块而不是Az.Storage。 Azure RM 中是否有与 Enable-AzStorageStaticWebsite 等效的 Cmdlet?

【问题讨论】:

标签: azure azure-powershell azure-rm


【解决方案1】:

不幸的是,现在Azure.Storage(GA) 模块中没有等效命令,您可以将Enable-AzureStorageStaticWebsiteAzure.Storage 4.4.1-preview 一起使用,但Az 模块是一个新的powershell 模块也适用于Azure 资源经理,你可以试试看。

如果您想使用Az 运行为AzureRM 开发的脚本,请使用Enable/Disable-AzureRmAlias cmdlet 将别名从AzureRM cmdlet 添加或删除到Az cmdlet。

更多详情请参考link

【讨论】:

    【解决方案2】:

    我强烈建议为此使用 Az 模块。在 AzureRM 中,静态网站是 Azure.Storage 中的预览:https://www.powershellgallery.com/packages/Azure.Storage/4.4.1-preview

    【讨论】:

      【解决方案3】:

      你也可以自己调用:

      #function to Enable static website for the Azure Storage account.
      Function Enable-AzureRmStorageStaticWebsite(
          [Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext] [Parameter(Mandatory = $true)] $Context,
          [string] [Parameter(Mandatory = $true)] $IndexDocument,
          [string] [Parameter(Mandatory = $true)] $ErrorDocument404Path
      ) {
          $sasToken = New-AzureStorageAccountSASToken -Context $Context `
              -Service Blob -ResourceType Service -Protocol HttpsOnly -Permission wla `
              -StartTime (Get-Date).AddHours(-1) -ExpiryTime (Get-Date).AddHours(4)
          $body = (@'
      <?xml version="1.0" encoding="utf-8"?>  
      <StorageServiceProperties>
      <StaticWebsite>
          <Enabled>true</Enabled>
          <IndexDocument>{0}</IndexDocument>
          <ErrorDocument404Path>{1}</ErrorDocument404Path>
      </StaticWebsite>
      </StorageServiceProperties>
      '@ -f $IndexDocument, $ErrorDocument404Path)
          $headers = @{"x-ms-version" = "2018-03-28"; "x-ms-date" = (Get-Date -Format R); "Content-Type" = "application/xml"; "Content-Length" = [string]$body.length }
          $apiUrl = ("{0}{1}&restype=service&comp=properties" -f $Context.BlobEndPoint, $sasToken)
          Write-Verbose ('Enable-AzureRmStorageStaticWebsite -IndexDocument {0} -ErrorDocument404Path {1}' -f $IndexDocument, $ErrorDocument404Path)
          Invoke-RestMethod -Method Put -Uri $apiUrl -Headers $headers -Body $body    
      }
      

      请确保您已安装模块Azure.Storage 支持存储 api-version '2018-03-28'(我相信 powershell-version: 4.4.1 或更高版本)

      【讨论】:

        猜你喜欢
        • 2012-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多