Open theDonOfBran opened 5 years ago
And it actually does cause an error when the code is running from Visual Studio Code.
Also getting this issue, and the suggested change of casting the value before it's assigned rather than casting the variable seems to fix it for me. There are 8 occurrences of this bug in WindowsCompatibility.psm1, with $verboseFlag
, $whatIfFlag
, and $confirmFlag
.
@Medve01 I see you've submitted a PR for the $verboseFlag
instances, but not the $whatIfFlag
or $confirmFlag
ones. I think it's cleaner to go with what @theDonOfBran suggested and do $verboseFlag = [bool]$PSBoundParameters['Verbose']
rather than defaulting to $false
and then checking whether it exists, since if its value hasn't been instantiated yet then casting it to a bool gives it a value of $false
anyway. I can't vouch for whether this fixes the bug on VSCode however.
Any updates on this one? How come you guys make it work? I got Cannot convert value "" to type "System.Boolean"
error on every Push-Location
and Import-WinModule
without explicit -Verbose
. I can contribute. But when will it be accepted with such a workflow??
@milichev What is PowerShell version you use?
Same issue here, I'm running version 7.0.3
Import-WinModule -Name WebAdministration
Cannot convert value "" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, | $False, 1 or 0.'
Running with the verbose flag works
Import-WinModule -Name WebAdministration -Verbose
https://github.com/PowerShell/WindowsCompatibility/blob/7b76e65d2a59a38dfd5db36c1441175da293a639/WindowsCompatibility/WindowsCompatibility.psm1#L150 could cause error:
I'm not sure if Write-Verbose cmdlet use in this project requires the Verbose parameter to be set, I'd remove it if not. https://github.com/PowerShell/WindowsCompatibility/blob/7b76e65d2a59a38dfd5db36c1441175da293a639/WindowsCompatibility/WindowsCompatibility.psm1#L157
If $verboseFlag is needed then please change all occurrences of:
[bool] $verboseFlag = $PSBoundParameters['Verbose']
to:$verboseFlag = [bool]$PSBoundParameters['Verbose']