I have a powershell script that prints a date, it does this via:
"$([DateTime]::Now)"
This produces a US format date of MM/DD/YYYY etc. I'm in the UK and would like this to come out as DD/MM/YYYY etc. I had thought that my server or shell was in the incorrect locale, so I added:
$culture = [system.globalization.cultureinfo]"en-GB"
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
To the top of my script - no difference, indeed, checking the locale at startup or in the shell reports that my locale is "en-GB".
I have now tried the following:
"$([DateTime]::Now.ToString())"
Which gives me a UK format date. I have therefore acheived what I want to do, but this is now a mystery, why does Powershell's string interpolation of a DateTime return a different result than .ToString()? Is this a defined or controllable behaviour?
Cheers,
Mark