Get the weekday and month with PowerShell in different languages

PowerShell uses the regional settings of Windows if the current date is queried via Get-Date

PowerShell

The settings can be checked with PowerShell via Get-Culture, and the detailed formats are shown in the Windows regional settings.

Local configuration for regional settings
Local configuration for regional settings

I would like to get a German name.

PowerShell
 Get-Date -Format "dddd, dd.MM.yyyy" OR
 Get-Date -Format "dddd, dd. MMMM yyyy"


The naming for weekday/month is not correct due to my English configuration

PowerShell

Instead of changing the regional settings, I can tell PowerShell which language it should use (once).

  • For the weekday
PowerShell
$RegionalCulture = New-Object System.Globalization.CultureInfo("de-CH")
$DayName = $RegionalCulture.DateTimeFormat.GetDayName((Get-Date).DayOfWeek)
$Date = ("$DayName, " + (Get-Date -format "dd.MM.yyyy"))
$RegionalCulture.TextInfo.ToTitleCase($Date) # to capitalize the first character of the day

PowerShell
  • For weekday and month

PowerShell also adapts the month’s name to the German name with a bit of addition.

PowerShell
$RegionalCulture = New-Object System.Globalization.CultureInfo("de-CH")
$DayName = $RegionalCulture.DateTimeFormat.GetDayName((Get-Date).DayOfWeek)
$MonthName = $RegionalCulture.DateTimeFormat.GetMonthName(((Get-Date).Month))
$Date = ("$DayName, " + (Get-Date -format "dd. MMMMM yyyy")).Replace((Get-Date -format MMMM),$MonthName)
$RegionalCulture.TextInfo.ToTitleCase($Date) # to capitalize the first character of day and month

PowerShell

The option can be changed to many languages by customizing the language once. Microsoft lists the regional language codes here. It also supports Romansh for Switzerland.

PowerShell
$RegionalCulture = New-Object System.Globalization.CultureInfo("rm-CH")
$DayName = $RegionalCulture.DateTimeFormat.GetDayName((Get-Date).DayOfWeek)
$MonthName = $RegionalCulture.DateTimeFormat.GetMonthName(((Get-Date).Month))
$Date = ("$DayName, " + (Get-Date -format "dd. MMMMM yyyy")).Replace((Get-Date -format MMMM),$MonthName)
$RegionalCulture.TextInfo.ToTitleCase($Date) # to capitalize the first character of day and month

PowerShell
Share
Avatar photo

Tobias Asböck

Tobias is a Senior System Engineer with around ten years of professional experience with Microsoft 365 products such as SharePoint Online, OneDrive for Business, Teams Collaboration, Entra ID, Information Protection, Universal Print, and Microsoft 365 Licensing. He also has 15+ years of experience planning, administering, and operating SharePoint Server environments. Tobias is a PowerShell Scripter with certifications for Microsoft 365 products. In his spare time, Tobias is busy with updates in the Microsoft 365 world or on the road with his road bike and other sports activities. If you have additional questions, please contact me via LinkedIn or [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *