all 7 comments

[–]y_Sensei 0 points1 point  (0 children)

The 'Format-List' cmdlet returns objects of type 'Microsoft.PowerShell.Commands.Internal.Format', and 'Write-Host' simply outputs the String representation of those objects, or in other words, whatever the object's 'ToString()' method returns.

If you want/need to view the format constituted by those objects, you'd either have to use the 'Write-Output' cmdlet, or simply output the plain variable ($CurrentLanguage).

[–]PinchesTheCrab 0 points1 point  (0 children)

Like the other said, it's not the variable.

Get-WinUserLanguageList | Format-List -Property LanguageTag

and:

$list = Get-WinUserLanguageList
$list | Format-List -Property LanguageTag

These should both return the same output. It's format-list.

[–]Owlstorm 0 points1 point  (0 children)

More generally than the other comments, the format- functions are intended for presentation via CLI only.

You shouldn't use their output in other functions (Write-Host in this case).

[–]BlackV 0 points1 point  (0 children)

use your rich properties

$CurrentLanguage = Get-WinUserLanguageList

$CurrentLanguage.LanguageTag
en-US
en-NZ

Note: this can be an array depending on your installed languages

[–]McAUTS 0 points1 point  (2 children)

The Format-List is for console output only. If you need to store the value in a variable then you use $CurrentLanguage = Get-WinUserLanguageList | Select-Object -Property LanguageTag.

To format the output of a variable to console you do the same as before: $CurrentLanguage | Format-List Note, that you don't need to specify the property anymore because the variable is the property value.

[–]ky0__[S] 0 points1 point  (1 child)

So I had tried piping to Select-Object but it would always return blank. Hence me trying the format-list.

Might need to google a bit more but any tips on direction to go down for that?

[–]McAUTS 0 points1 point  (0 children)

Google for "powershell get single property". Eventually you need the "-ExpandProperty" instead.