Powershell studio handling dates differently to powershell ISE

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
Isaac99
Posts: 17
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Fri Dec 13, 2019 4:37 am

Powershell studio handling dates differently to powershell ISE

Post by Isaac99 »

My form is getting last boot time from remote machine as follows:

$lastboot = (Get-WmiObject win32_operatingsystem | select csname, @{LABEL = 'LastBootUpTime'; EXPRESSION = { $_.ConverttoDateTime($_.lastbootuptime) }}).lastbootuptime

$richtextboxLastBoot.Text = $($lastboot)

When I run in Powershell I get the expected result - I am in the UK

01 March 2020 00:53:50

When I run it in the Powershell studio GUI it is returning the following in US date format:

03/01/2020 00:53:50

Any ideas?

User avatar
Alexander Riedel
Posts: 7376
Joined: Tue May 29, 2007 4:43 pm

Re: Powershell studio handling dates differently to powershell ISE

Post by Alexander Riedel »

The PowerShell console behaves differently than other hosts, even the ISE.
It's probably best to take full control of that in your script.

Set-Culture "en-GB"
is probably a good bet.

Then using
$d = Get-Date
$d.GetDateTimeFormats()
You can see the various formats available
I am guessing
$d = Get-Date
$d.GetDateTimeFormats()[25]
would be what you look for.
Alexander Riedel
SAPIEN Technologies, Inc.

Isaac99
Posts: 17
Joined: Fri Dec 13, 2019 4:37 am

Re: Powershell studio handling dates differently to powershell ISE

Post by Isaac99 »

awesome that works a treat, thank you

Locked