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.
This topic is 4 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Isaac99
Posts: 17
Last visit: Thu Apr 02, 2020 3:14 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: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

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
Last visit: Thu Apr 02, 2020 3:14 am

Re: Powershell studio handling dates differently to powershell ISE

Post by Isaac99 »

awesome that works a treat, thank you
This topic is 4 years and 3 weeks old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked