Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Powershell to customize "Region and Language" settings in win7 or win2008

I am new to Powershell and I have searched the internet for whole day but still cannot find out how to customize "Region and Language" settings using Powershell in win7 or win2008.

I want to change the following settings within Powershell:

  1. Current System Locale

  2. Short Date and Long Date format

  3. Short Time and Long Time format

  4. Current Location

Anybody knows how to do that using Powershell? Cmd/Bat/.NET solutions also welcome!

like image 518
Leo Avatar asked Dec 27 '22 04:12

Leo


2 Answers

I know your question was about Windows 7; this information may be helpful for those now running newer versions. Set-WinUserLanguageList, New-WinUserLanguageList and Get-WinUserLanguageList in Windows 8 and up let you control the installed languages. For example to add a language:

$list = Get-WinUserLanguageList
$list.Add("fr-FR")
Set-WinUserLanguageList $list

Set-Culture in PowerShell 3 lets you change culture, for example to choose defaults for Germany:

Set-Culture de-DE

Or, to set custom formats:

$culture = Get-Culture
$culture.DateTimeFormat.ShortDatePattern = 'yyyy-MM-dd'
$culture.DateTimeFormat.LongDatePattern = 'dddd, d MMMM yyyy'
$culture.DateTimeFormat.ShortTimePattern = 'h:mm tt'
$culture.DateTimeFormat.LongTimePattern = 'h:mm:ss tt'
Set-Culture $culture

To change the location, use Set-WinHomeLocation, for example to set the user's location to Austria:

Set-WinHomeLocation -GeoId 14

MSDN has a list of GeoIds and a TechNet has a reference for international settings cmdlets.

like image 194
Marc Durdin Avatar answered Dec 29 '22 18:12

Marc Durdin


@bourne lead me to

& $env:SystemRoot\System32\control.exe "intl.cpl,,/f:`"c:\setKeyboardUK.xml`""

Note the lack of a space between the ,, and /f, the use of quotes around the whole thing and the back tick to escape the quotes around the path (that are necessary).

This is my setKeyboardUK.xml file

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend"> 
<!--User List-->
<gs:UserList>
    <gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/> 
</gs:UserList>
<gs:UserLocale> 
    <gs:Locale Name="en-GB" SetAsCurrent="true"/> 
</gs:UserLocale>
<!--location--> 
<gs:LocationPreferences> 
    <gs:GeoID Value="242"/> 
</gs:LocationPreferences>
<gs:InputPreferences>
    <!--en-GB--> 
    <gs:InputLanguageID Action="add" ID="0809:00000809" Default="true"/> 
</gs:InputPreferences>

To check if the settings are applied(because failures are silent) open Event Viewer and "Application and Services Logs" then "Microsoft", "Windows", "International","Operational" any successful changes or failures are logged here(the logging is enabled by default).

FYI I did all this on Powershell 3 on Windows 2008 R2 64bit. YMMV

like image 41
rob Avatar answered Dec 29 '22 18:12

rob