Azure RM PowerShell 模块中的 Enable-AzStorageStaticWebsite 命令

Enable-AzStorageStaticWebsite command in Azure RM PowerShell module

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

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

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

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

更多详细信息,请参阅此link

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

你也可以自己调用:

#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 或更高)