I'd like to automate preferences on a Windows machine for the date and time formats used throughout the OS.
What PowerShell commands can I use to automate this task of changing values?
These options are buried deep in Control Panel.
I believe the settings you are looking for are located in:
HKEY_CURRENT_USER\Control Panel\International\sLongDate
HKEY_CURRENT_USER\Control Panel\International\sShortDate
HKEY_CURRENT_USER\Control Panel\International\sTimeFormat
HKEY_CURRENT_USER\Control Panel\International\sYearMonth
So,
Set-ItemProperty -Path "HKCU:\Control Panel\International"
-name sLongDate -value "<Whatever format you'd like>"
Based on p.campbells's answer, but with all properties:
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sCountry -Value "Germany";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sLongDate -Value "dddd, d. MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortDate -Value "dd.MM.yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortTime -Value "HH:mm";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sTimeFormat -Value "HH:mm:ss";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sYearMonth -Value "MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name iFirstDayOfWeek -Value 0;
Full example based on p.campbell's answer:
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sCountry -Value "Germany";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sLongDate -Value "dddd, d. MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortDate -Value "dd.MM.yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortTime -Value "HH:mm";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sTimeFormat -Value "HH:mm:ss";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sYearMonth -Value "MMMM yyyy";
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name iFirstDayOfWeek -Value 0;
To set the settings of the default user instead of the system, use HKU:\.DEFAULT\Control Panel\International
. For a specific user use HKU:\(UserSID)\Control Panel\International
.
To get the SID of the current user, use
([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value
If you don't have HKU:
mapped, use
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With