PowerShell - Display months or days of the week in the desired culture

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!

Hello,

If you want to display the months or days of the week as a string value in the desired culture to embed in logs or reports, here’s how to do it in Powershell.

# Display the names of the months in the culture used.
1..12 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetMonthName($_)}
# Display the names of the abbreviated months in the crop used
1..12 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($_)}
# Display the names of the days of the week in the culture used
0..6 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetdayName($_)}
# The week starts on Sunday
# Display the names of the abbreviated days of the week in the culture used
0..6 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetAbbreviatedDayName($_)}
# Display the 1st letter of the days of the week in the culture used
0..6 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetshortestdayName($_)}
# Display month names in another culture
$Culture = 'en-us'
1..12 | ForEach-Object -process {[cultureinfo]::GetCultureInfo($Culture).DateTimeFormat.GetMonthName($_)}
# Display the names of the abbreviated month in another culture
1..12 | ForEach-Object -process {[cultureinfo]::GetCultureInfo($Culture).DateTimeFormat.GetAbbreviatedMonthName($_)}
# Display the names of the days of the week in another culture
0..6 | ForEach-Object -process {[cultureinfo]::GetCultureInfo($Culture).DateTimeFormat.GetdayName($_)}
# Display the names of the abbreviated days of the week in another culture
0..6 | ForEach-Object -process {[cultureinfo]::GetCultureInfo($Culture).DateTimeFormat.GetAbbreviatedDayName($_)}
# Display the 1st letter of the days of the week in another culture
0..6 | ForEach-Object -process {[cultureinfo]::GetCultureInfo($Culture).DateTimeFormat.GetshortestdayName($_)}
# You can also change the culture directly in the Powershell environment
[cultureinfo]::CurrentCulture = 'en-us
# Display the names of the months in the culture used
1..12 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetMonthName($_)}
# Display the names of the abbreviated months in the crop used
1..12 | ForEach-Object -process {(Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($_)}
# List all available cultures
# Windows Powershell
[System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::AllCultures)
# Powershell 7
Get-Culture -ListAvailable

Related links