I noticed my PSU runs on "en-US" because I get (crazy ;) ) dates like month/day/year instead of logical day/month/year
How can I change this? without having to set in my scripts?
Thanks
Hello Denis,
Thank you for your question.
PowerShell Universal does not have its own culture setting for scripts.
Each job takes its culture from the Windows account that runs PowerShell Universal.
By default, the PowerShell Universal service runs as Local System.
That account keeps the regional format chosen when Windows was installed, which is often English (United States).
You can check what your jobs see by running this short script once in PowerShell Universal:
[cultureinfo]::CurrentCulture.Name
[cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern
To change it for all scripts at once, copy your regional format to the system accounts on the server:
Sign in to the PowerShell Universal server with an administrator account and open Control Panel > Region.
On the Formats tab, pick the format you want, for example Dutch (Belgium), and click Apply.
On the Administrative tab, click Copy settings.
Check "Welcome screen and system accounts", then click OK.
Restart the server.
Microsoft states that this change takes effect after a restart, so please plan a short maintenance window.
If the service runs under a dedicated account instead of Local System, you will see it on the Log On tab of the service in services.msc.
In that case, sign in once as that account, set the format in the Region settings, and restart the service.
Scripts that use a Run As credential take the format of that account, so set it there as well.
API endpoints that run in the Integrated environment are an exception.
They use the language of the incoming request instead.
PowerShell Universal only supports English (United States), French and Danish there, so other languages fall back to month/day/year.
If your endpoints need your regional format, set them to the PowerShell 7 or Windows PowerShell 5.1 environment.
Those environments follow the Windows setting, like scripts do.
One PowerShell behavior is worth knowing before you test.
PowerShell always uses the US format, month then day, when a date is placed in a double-quoted string such as "$(Get-Date)", or cast with [datetime].
This is by design in PowerShell and does not depend on the server culture.
To get the server format, use $date.ToString(), Get-Date -Format d, or "{0}" -f $date instead.
The dates shown in the admin console itself do not follow this Windows setting either.
If those are the dates you meant, let me know and I will log a feature request.
If your server runs on Linux or in Docker rather than Windows, let me know and I will send the matching steps.
Here are the related pages:
https://docs.devolutions.net/powershell-universal/getting-started/
https://docs.devolutions.net/powershell-universal/automation/scripts/
Best regards,
Patrick Ouimet
Hi,
Thank you for your reply.
I'm running the service as a group managed service account.
So I can't really log in as that and change regional settings.
Hello Denis,
Thank you for the detail, a group managed service account changes the approach.
You do not need to sign in as the gMSA.
When a job has no Run As credential, PowerShell Universal runs it as the service account, so a job can change the gMSA's own regional format.
The Set-Culture cmdlet sets the culture for the account that runs it.
Here is how to apply it once:
In the admin console, go to Automation > Scripts, create a new script, and set its environment to Windows PowerShell 5.1.
Paste the lines below, and replace nl-BE with the format you want, for example fr-BE.
whoami
Set-Culture -CultureInfo nl-BE
Run the script once, and check that the whoami output shows your gMSA name.
Restart the PowerShell Universal service so that new jobs pick up the change.
Microsoft states that Set-Culture takes effect in new PowerShell sessions, which is why the restart is needed.
To confirm, run these two lines in a new job:
[cultureinfo]::CurrentCulture.Name
(Get-Date).ToString()
The first line should show nl-BE, and the date should now show the day first.
You can then delete the one-time script.
The rest of my last message still applies, including the fixed format of dates inside "$(Get-Date)" strings.
If you would rather not run this from PowerShell Universal, let me know and I will send a registry method instead.
Here is the Microsoft page for the cmdlet:
Best regards,
Patrick Ouimet