Tuesday, March 5, 2019

Azure @ Enterprise - Write-Host v/s Write-Output in Kudu console

Recently we were troubleshooting in one Azure WebAppBot application. It needs certificates to access some secrets from Azure KeyVault. After some debugging, we reached to a place where we suspect that the certificates added are not getting accessed by the WebApp. So we decided to test the availability of certificates using Kudu PowerShell console.

Get-childitem Cert:\CurrentUser\My -recurse | %{ write-host $_.Subject }

Unfortunately we got some other issue.

PS D:\home> Get-childitem Cert:\CurrentUser\My -recurse | %{ write-host $_.Subject ; }
Get-childitem Cert:\CurrentUser\My -recurse | %{ write-host $_.Subject ; }
write-host : The Win32 internal error "The handle is invalid" 0x6 occurred
PS D:\home>
while setting character attributes for the console output buffer. Contact Microsoft Customer Support Services. At line:1 char:50 + ... hilditem Cert:\CurrentUser\My -recurse | %{ write-host $_.Subject ; } + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [Write-Host], HostExcep tion + FullyQualifiedErrorId : SetConsoleTextAttribute,Microsoft.PowerShell.Com mands.WriteHostCommand

It seems the PowerShell capabilities what we have in VMs is not the same what we have in WebApp's Kudu console. Even a simple Write-Host "Hi" also failed.

So tried to use Write-Output instead of Write-Host which writes to stream than to the host.

It worked!!!

Happy debugging.

No comments: