Skip to content
This repository was archived by the owner on Jun 16, 2021. It is now read-only.
This repository was archived by the owner on Jun 16, 2021. It is now read-only.

Type conversion issue on setting $verboseFlag  #68

Description

@theDonOfBran

[bool] $verboseFlag = $PSBoundParameters['Verbose']
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.

Write-Verbose -Verbose:$verboseFlag "Initializing the compatibility session on host '$ComputerName'."

If $verboseFlag is needed then please change all occurrences of:
[bool] $verboseFlag = $PSBoundParameters['Verbose']
to:
$verboseFlag = [bool]$PSBoundParameters['Verbose']

Activity

  1. Medve01 commented on May 31, 2019

    @Medve01

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

  2. irisxzhou commented on Jul 25, 2019

    @irisxzhou

    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.

    Bear (@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.

  3. milichev commented on May 4, 2020

    @milichev

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

  4. iSazonov commented on May 4, 2020

    @iSazonov

    Vadym Milichev (@milichev) What is PowerShell version you use?

  5. WagnerJanissetti commented on Oct 1, 2020

    @WagnerJanissetti

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions