Share via


How to change language in Powershell (to english)?

Question

Wednesday, April 27, 2011 5:20 PM | 2 votes

Hi,

is there any chance how to change Powershell language? I use Win7 Professional 32bit Czech language. I havent found any possibility to change language to english.

Thanks for advice.

All replies (11)

Thursday, April 28, 2011 5:26 PM ✅Answered

No and no.

First. Put the function in your script.

Here I am opening up Excel and doing stuff:

#< Begin script >

function Remove-ComObject {
 # Requires -Version 2.0
 [CmdletBinding()]
 param()
 end {
  Start-Sleep -Milliseconds 500
  [Management.Automation.ScopedItemOptions]$scopedOpt = 'ReadOnly, Constant'
  Get-Variable -Scope 1 | Where-Object {
   $_.Value.pstypenames -contains 'System.__ComObject' -and -not ($scopedOpt -band $_.Options)
  } | Remove-Variable -Scope 1 -Verbose:([Bool]$PSBoundParameters['Verbose'].IsPresent)
  [gc]::Collect()
 }
}

Function Using-Culture (
[System.Globalization.CultureInfo]$culture,
[ScriptBlock]$script)
{
    $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
    trap
    {
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
    }
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
    $ExecutionContext.InvokeCommand.InvokeScript($script)
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
} # End Function

Using-Culture en-us {
$xl= New-Object -COM Excel.Application
$xl.Visible = $true
$xl.DisplayAlerts = $False
$xl.Workbooks.Open("C:\Scripts\PowerShell\test.xls")

$xl.quit()
Remove-ComObject -Verbose
Start-Sleep -Milliseconds 250
Get-Process Excel
#[System.Runtime.InteropServices.Marshal]::ReleaseComObject($xl)
}
# ======================End Script ================================

 Basicaly, you have to load the function before you use it. You could also add the function to your profile.ps1, then it would be loaded every time you start Powershell.

 

 


Wednesday, April 27, 2011 5:30 PM

there is a default variable PSCulture that is en-US on my machine...  as well as PSUICulture which is also en-US

maybe change those and see what happens? do you have the en-us culture installed on your machine?


Wednesday, April 27, 2011 6:04 PM

$PSUICulture

en-US

 

$PSUICulture

cs-CZ

 

PS C:\Documents and Settings\polo> $PSUICulture="en-US"
Cannot overwrite variable PSUICulture because it is read-only or constant.
At line:1 char:13

  • $PSUICulture <<<< ="en-US"
        + CategoryInfo          : WriteError: (PSUICulture:String) [], SessionStateUnauthorizedAccessException
        + FullyQualifiedErrorId : VariableNotWritable

I can not change the variable:(


Wednesday, April 27, 2011 6:28 PM

You can change the Current Thread’s Culture or pass the Culture to .Net Static Methods’ <System.IFormatProvider> argument.

I blogged about Standard Formatting Strings, Numeric and Date Time; I used both techniques, see the Cultue Specific section, Explicit passes the Culture to .Net Static Methods’ <System.IFormatProvider> argument while Implicit changes the Current Thread’s Culture.

  Robert Robelo  


Wednesday, April 27, 2011 7:56 PM

You could try this: At the begining of your script:

Function Using-Culture (
[System.Globalization.CultureInfo]$culture,
[ScriptBlock]$script)
{
    $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
    trap
    {
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
    }
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
    $ExecutionContext.InvokeCommand.InvokeScript($script)
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
} # End Function

Using-Culture en-us {   Your script here    }


Thursday, April 28, 2011 12:57 PM

I have got your function to the script sc.ps1 and I started it.

PS C:\Documents and Settings\polo> .\sc.ps1

Here I tested the script.

PS C:\Documents and Settings\polo> Using-Culture en-us { get-command }
The term 'Using-Culture' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14

  • Using-Culture <<<<  en-us { get-command }
        + CategoryInfo          : ObjectNotFound: (Using-Culture:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

Thursday, April 28, 2011 1:38 PM

So, did you put the function at the begining of your script? Or you could add it to your profile so it would always be available.


Thursday, April 28, 2011 1:44 PM

Hello,

I tried the following, but it didnt work.

PS C:\Documents and Settings\polo> [Threading.Thread]::CurrentThread.CurrentCulture = 'is-IS'; '{0:D}' -f (winrm quickco
nfig -transport:https); '{0:C}'

Dont notice that I used is-IS, I just tried if it works. I need translate the output of "winrm quickconfig -transport:https", because I have problems with configuration of this service.

Thanks a lot for advice.


Thursday, April 28, 2011 3:53 PM

No I put the function to the script sc.ps1. And then:

1]I called the script

2] I called function with command as a parameter.


Thursday, April 28, 2011 5:07 PM

Could I please see your full script?


Thursday, April 28, 2011 5:15 PM

Function Using-Culture (
[System.Globalization.CultureInfo]$culture,
[ScriptBlock]$script)
{
    $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
    trap
    {
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
    }
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
    $ExecutionContext.InvokeCommand.InvokeScript($script)
    [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
} # End Function

Thats the whole content of my script. Just the function... After I started the script so I called the function:

PS C:\Documents and Settings\polo> Using-Culture en-us { winrm quickconfig -transport:https }
The term 'Using-Culture' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:14

  • Using-Culture <<<<  en-us { winrm quickconfig -transport:https }
        + CategoryInfo          : ObjectNotFound: (Using-Culture:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException