Quantcast
Channel: PowerShell, formatting values in another culture - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Keith Hill for PowerShell, formatting values in another culture

$
0
0

This is a PowerShell function I use for testing script in other cultures. I believe it could be used for what you are after:

function Using-Culture ([System.Globalization.CultureInfo]$culture =(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"),                        [ScriptBlock]$script=(throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}")){        $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture    $OldUICulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture    try {        [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture        [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture                Invoke-Command $script        }        finally {                [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture                [System.Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture        }    }PS> $res = Using-Culture fr-FR { 1.1 }PS> $res1.1

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>