Skip to content

ParameterBindingValidationException exception thrown when $PSUICulture not en-US #382

Open
@stuart938503

Description

@stuart938503

Prelims:

PS C:\Windows\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1237
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS C:\Windows\system32> [environment]::OSVersion.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19043  0
PS C:\Windows\system32> Get-Module -Name LabBuilder

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.2.0      LabBuilder                          {Connect-LabVM, Disconnect-LabVM, Get-Lab, Get-LabResourceISO...}

On installing the above version of LabBuilder and trying to Install-Lab, a ParameterBindingValidationException exception is thrown:

PS C:\Windows\system32> Install-Lab -ConfigPath D:\VMs\Labs\MIM1\Configuration.xml -Verbose
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'True'; IsRegistered = 'True'.
Write-LabMessage : Cannot validate argument on parameter 'Message'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Program Files\WindowsPowerShell\Modules\LabBuilder\1.2.0\LabBuilder.psm1:9729 char:35
+ ... te-LabMessage -Message $($LocalizedData.InitializingLabFoldersMesage)
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Write-LabMessage], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Write-LabMessage

<lines omitted for brevity - all related to the above>

Inspecting LabBuilder.psm1, it appears $LocalizedData is not set. It should be set under lines 11-31:

#region LocalizedData
$culture = $PSUICulture

if ([System.String]::IsNullOrEmpty($culture))
{
    $culture = 'en-US'
}
else
{
    if (Test-Path -Path (Join-Path -Path $script:LabBuidlerModuleRoot -ChildPath $culture))
    {
        $culture = 'en-US'
    }
}

Import-LocalizedData `
    -BindingVariable LocalizedData `
    -Filename 'LabBuilder.strings.psd1' `
    -BaseDirectory $script:LabBuidlerModuleRoot `
    -UICulture $culture
#endregion

This should set $culture to en-US if $PSUICulture is empty, or if a path does not exist for the local culture data. This fails however as the Test-Path if statement will only set it to en-US if the path exists. I believe the result of Test-Path should be negated.

My own culture is:

PS C:\Windows\system32> $PSUICulture
en-GB

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug.help wantedThe issue is up for grabs for anyone in the community.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions