0

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

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

在此处输入图像描述

4

3 回答 3

2

Azure.Storage不幸的是,现在(GA)模块中没有等效的命令 ,您可以使用Enable-AzureStorageStaticWebsitewith Azure.Storage 4.4.1-preview,但该Az模块是Azure Resource Manager的新 powershell 模块,您可以尝试一下。

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

有关更多详细信息,请参阅此链接

于 2018-12-18T06:22:48.627 回答
1

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

于 2018-12-18T18:06:00.423 回答
1

你也可以自己调用它:

#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    
}

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

于 2019-06-20T10:17:06.867 回答