We have a PowerShell script that contains "[Console]::TreatControlCAsInput = $true". The script is executed in a Azure DevOps Pipeline and fails with
Exception setting "TreatControlCAsInput": "The handle is invalid.
"
At line:1 char:3
+ [Console]::TreatControlCAsInput = $true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
We've narrowed down the issue by reproducing this with a single line of code outside of an Azure Pipeline. Simply open Windows PowerShell ISE and run this:
[Console]::TreatControlCAsInput = $true
If we do this in a Windows PowerShell command window, the line of code succeeds.
Does anyone know what is different about the two environments that causes this difference in behavior? We are hoping that the answer would help us understand and resolve the larger issue with the script that runs in an Azure Pipeline.
The script runs fine if executed:
- In Cmd.exe window using Powershell.exe -File ....
- In Windows PowerShell window
The script fails if executed in WIndows PowerShell ISE