PowerShell / WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
Other
137 stars 33 forks source link

Type conversion issue on setting $verboseFlag #68

Open theDonOfBran opened 5 years ago

theDonOfBran commented 5 years ago

https://github.com/PowerShell/WindowsCompatibility/blob/7b76e65d2a59a38dfd5db36c1441175da293a639/WindowsCompatibility/WindowsCompatibility.psm1#L150 could cause error:

Cannot convert value "" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.

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']

Medve01 commented 5 years ago

And it actually does cause an error when the code is running from Visual Studio Code.

irisxzhou commented 4 years ago

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.

milichev commented 4 years ago

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??

iSazonov commented 4 years ago

@milichev What is PowerShell version you use?

WagnerJanissetti commented 3 years ago

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