0

I am trying to run powershell script as Azure Web Job (simple one that comes with WebApps) that is responsible for creating PDF file and uploading that file to Azure Blob Storage. When file is successfully created there is an error during file upload using following commands:

$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

As a result I have following message that is displayed in Azure Web Jobs logs (in Kudu portal).

[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

Same script works correctly on my local machine. What is more when I created webjob just to list available modules using Get-Module -ListAvailable i received modules with following ones as well.

    ...
[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...
...

1 Answer 1

2

According to your description, I could reproduce your issue. After some trials, I assumed that it was due to PowerShell Progress Indicators which provides progress indicators in the UI during long-running operations. You could try to disable progress indicators in Power Shell by executing the following command before you call Set-AzureStorageBlobContent:

$ProgressPreference="SilentlyContinue"

Sign up to request clarification or add additional context in comments.

2 Comments

The reason is that progress bar cannot be projected on remote Web UI of the shell, please disable every time you refresh or navigate to SCM web-based PS console. Refer to this issue: github.com/projectkudu/kudu/issues/2172
Solution proposed by Bruce is exactly what I was looking for. Now everything works correctly. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.