kafka kafka - 1 year ago 114
PowerShell Question

Is there a simpler way to work with UK date format in Powershell?

To work with UK date format, as is my preference, the following code snippet will get me a UK date format (Powershell does not take into account machine locale).

$UKdate = [datetime]::Parse($req.ServicePoint.Certificate.GetExpirationDateString(),([Globalization.CultureInfo]::CreateSpecificCulture('en-GB')))

This seems unwieldy, particularly when the language is normally so concise. Is there a better way that I'm not aware of?

Answer Source

PowerShell does take the locale into account, but casting to [DateTime] does not.

That is, if you were to run this with a UK culture it'll parse it as a UK date:

Get-Date $req.ServicePoint.Certificate.GetExpirationDateString()

Where as this will always choose en-US:



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download