Azure Automation Runbook: Get-Date Formatting to 'yyyy-MM-ddTHH:mm:ss' does not work properly

Dustin 0 Reputation points
2025-06-18T08:25:51.57+00:00

Dear folks,

For an API I need a DateTime string in the format "yyyy-MM-ddTHH:mm:ss, or at least just the date, the time can be zero. It seems this specific string does cause issues in a runbook. It will default to the default locale DateTime. So say I do the following:

Get-Date -Format "yyyy-MM-ddTHH:mm:ss"

The expected result should be "2025-06-17T08:37:54", but the current result will print: "6/17/2025 8:37:54 AM" regardless of what I try with it.

It seems if I change the format to "dd-MM-yyyyTHH:mm:ss" it works fine, making me assume the format "yyyy-MM-ddTHH:mm:ss" is causing the problem.
After fiddling around, it seems that the month is the issue. Why I am not sure, but for some reason if I remove one 'M' in the month, then. I get the the (almost) wanted output of "2025-6-17T08:37:54". It also seems to be a general platform issue, PowerShell 5.1 also has the same issue.

I use PowerShell 7.4 for my runbooks.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,366 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.