我正在尝试将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/