GET-AzureBlobContent抛出错误从Azure的自动化帐户下运行时(Get-Azure

2019-09-29 05:02发布

我收到一个失败,而试图从我的Azure的自动化帐户下载从Azure存储帐户的blob(JSON文件)。 它看起来像一个授权问题。

这适用于我的本地笔记本电脑,但在Azure上自动化帐户不起作用。 如果我做容器“公共”甚至不工作

我已分配的资源组(自动化帐户+存储帐户留在这个RG)自动化账户的服务宗旨,并专门对存储账户以及所有者权限:

下面是代码:

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

$config_file_resource_group_name = "vg-datalake-manjunath"
$config_file_storage_account_name = "datalakelog"
$primary_key = (Get-AzureRmStorageAccountKey -ResourceGroupName $config_file_resource_group_name -AccountName $config_file_storage_account_name).value[0]
 $config_file_context = New-AzureStorageContext -StorageAccountName $config_file_storage_account_name -StorageAccountKey $primary_key

 Get-AzureStorageBlobContent -Blob "mw_services.json" -Container "fwconfigfiles" -Destination "C:\temp\mw_services.json" -Context $config_file_context

 get-content "C:\temp\mw_services.json" | write-output

错误:

Get-AzureStorageBlobContent : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error 
Message: This request is not authorized to perform this operation.
At line:30 char:2
+  Get-AzureStorageBlobContent -Blob "mw_services.json" -Container "fwc ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureStorageBlobContent], StorageException
    + FullyQualifiedErrorId : 
StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageBlobContentCommand

Answer 1:

可能的原因是,你可以配置到选定的网络访问。

如果启用该选项,以及是否勾选“允许受信任的Microsoft服务访问”,你会得到这个错误,因为自动化未列在MS值得信赖的服务。 看到https://docs.microsoft.com/en-us/azure/storage/common/storage-network-security#trusted-microsoft-services 。



文章来源: Get-AzureBlobContent throwing error when run from Azure Automation account