powershell - 使用 Powershell 脚本将文件上传到 Azure Blob 存储的 Azure WebJob

标签 powershell azure azure-storage azure-webjobs

我正在尝试将powershell脚本作为Azure Web Job(WebApps附带的简单任务)运行,负责创建PDF文件并将该文件上传到Azure Blob存储。成功创建文件后,使用以下命令上传文件时出现错误:

$pdfFileName = $reportId + ".pdf";
$storageAccountName = "MY-STORE"
$storageAccountKey = "MY-KEY"
$containerName = "_MY_CONTAINER"
$fullFileName = $PSScriptRoot + "\" + $pdfFileName

$ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Set-AzureStorageBlobContent -File "$fullFileName" -Container $containerName -Blob $pdfFileName -Context $ctx -Force

因此,我在 Azure Web 作业日志(在 Kudu 门户中)中显示了以下消息。

[11/15/2016 15:20:24 > 89499f: ERR ] Set-AzureStorageBlobContent : Win32 internal error "The handle is invalid" 0x6 
[11/15/2016 15:20:24 > 89499f: ERR ] occurred while reading the console output buffer. Contact Microsoft Customer 
[11/15/2016 15:20:24 > 89499f: ERR ] Support Services.
[11/15/2016 15:20:24 > 89499f: ERR ] At 
[11/15/2016 15:20:24 > 89499f: ERR ] D:\local\Temp\jobs\triggered\ddd\orgmoz1g.dqi\generateAndUploadReports.ps1:53 
[11/15/2016 15:20:24 > 89499f: ERR ] char:3
[11/15/2016 15:20:24 > 89499f: ERR ] +      Set-AzureStorageBlobContent -File $fullFileName -Container 
[11/15/2016 15:20:24 > 89499f: ERR ] $containerName -Blo ...
[11/15/2016 15:20:24 > 89499f: ERR ] +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[11/15/2016 15:20:24 > 89499f: ERR ] ~~~~~~
[11/15/2016 15:20:24 > 89499f: ERR ]     + CategoryInfo          : ReadError: (:) [Set-AzureStorageBlobContent], Ho 
[11/15/2016 15:20:24 > 89499f: ERR ]    stException
[11/15/2016 15:20:24 > 89499f: ERR ]     + FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.WindowsAzure.Command 
[11/15/2016 15:20:24 > 89499f: ERR ]    s.Storage.Blob.SetAzureBlobContentCommand

相同的脚本在我的本地计算机上可以正常运行。更重要的是,当我创建 webjob 只是为了使用 Get-Module -ListAvailable 列出可用模块时,我也收到了包含以下模块的模块。

    ...
[11/15/2016 15:40:36 > 89499f: INFO] ModuleType Version    Name                                ExportedCommands     
[11/15/2016 15:40:36 > 89499f: INFO] ---------- -------    ----                                ----------------     
[11/15/2016 15:40:36 > 89499f: INFO] Manifest   1.4.0      Azure                               {Get-AzureAutomati...
...
[11/15/2016 15:40:36 > 89499f: INFO] ModuleType Version    Name                                ExportedCommands     
[11/15/2016 15:40:36 > 89499f: INFO] ---------- -------    ----                                ----------------     
[11/15/2016 15:40:36 > 89499f: INFO] Manifest   1.1.2      Azure.Storage                       {Get-AzureStorageB...
...

最佳答案

根据您的描述,我可以重现您的问题。经过一番尝试,我认为这是由于 PowerShell Progress Indicators它在长时间运行的操作期间在 UI 中提供进度指示器。您可以尝试在调用 Set-AzureStorageBlobContent 之前执行以下命令来禁用 Power Shell 中的进度指示器:

$ProgressPreference="SilentlyContinue"

关于powershell - 使用 Powershell 脚本将文件上传到 Azure Blob 存储的 Azure WebJob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40614035/

相关文章:

Azure 表存储并行查询

c# - 无法对 Azure 存储表查询 lambda 内的字符串属性使用基于字符串的方法

powershell - 将PC添加到域并同时更改名称的问题

git - 在 Powershell 中执行 git 命令

powershell - CIMSessions 需要哪些权限

powershell - 按 Import-CSV 中的最大数值对对象进行排序

azure - 如果我使用 MemoryStream,为什么 Azure UploadFromStream 不起作用(可以起作用,但长度等于 0)?

Azure APIM 策略改变有效负载主体

azure - CosmosDB Graph API/Gremlin API RU 计算器

c# - Azure Cosmos DB 通过 C# 代码将集合 TTL 设置为 - on(无默认值)