I’m sure there is some easy resolution for this, but my coffee hasn’t kicked in yet…
My script needs to pull back remote session information from a Horizon View VDI environment and output a table showing the username, VDI pool, VDI name, and how long the user has been logged in. Most of that has been no problem, but I want the logged in duration column to be sorted.
From this code you can see that Get-RemoteSession returns 2 properties that can be used to create that column: startTime and duration. Unfortunately, neither of those are in a format that is sortable…
PS C:\scripts> Get-RemoteSession -username domain.com\user1 | Select-Object Username, pool_id, DNSName, starttime, duration Username : domain.com\user1 pool_id : network7vm DNSName : NETWORK7VM2.domain.com startTime : Thu Sep 11 10:29:33 CDT 2014 duration : 62 days 0 hours 41 minutes
Using ParseExact, I can convert startTime to a DateTime object, which is sortable.
PS C:\scripts> [datetime]::ParseExact("Thu Sep 11 10:29:33 CDT 2014", "ddd MMM dd HH:mm:ss CDT yyyy", $null)
Thursday, September 11, 2014 10:29:33 AM
The problem, though, is that some of the users are coming back with “CST” instead of “CDT” for the time zone, (I realize that probably indicates another problem with NTP somewhere in the View environment, but I’ll mess with that later…). How do I convert that startTime field into a DateTime when the time zone abbreviation isn’t consistent?
Thu Sep 11 10:29:33 CDT 2014 Wed Nov 12 07:11:51 CST 2014