ToShortTimeString() vs .Converttodatetime( )

Hi All

I am doing a wmi query (Get-WmiObject -Class Win32_OperatingSystem) and im looking to format the LastBootUpTime

Select-Object CSName,@{ Name = “Last Restarted On” ; Expression = { $.Converttodatetime( $.LastBootUpTime ) } }

I am currently using the Converttodatetime( ) method, is there any way to use the ToShortTimeString() , im not opposed to builidng a hash table with that method either . im looking for just the Time no seconds .eg 11:00

thank you

Ill be using this rt do some conditional html formatting

[xml]$html = $Reboot   | ConvertTo-Html -fragment

#check each row, skipping the TH header row
for ($i=1;$i -le $html.table.tr.count-1;$i++) {
  $class = $html.CreateAttribute("class")
  #check the value of the last column and assign a class to the row
  if (($html.table.tr[$i].td[-1] -as [datetime]) -notlike '*11:00*') {                                          
    $class.value = "danger"  
    $html.table.tr[$i].Attributes.Append($class) | Out-Null
  }
  
} 

not sure if my conditional statement is on point

im looking to mark red all computers that didn’t reboot @ 11:00

You should be able to do this:

$_.Converttodatetime($_.LastBootUpTime).ToShortTimeString()

thanks again Dave! really appreciate your help today

Also, if you query the class using Get-CimInstance, you’ll get a DateTime by default.

For future posts, please try not to reply to your own post. A lot of us look for “topics without a reply” as a way of finding posts that need answered; when you reply to your own topic, sometimes that keeps your topic from being seen by folks who might be able to help. Instead, try to think about your post and include all the needed information up front. You can edit the original post to add more information, if something occurs to you before someone is able to reply. Thanks.

ok Don Will do ! and thanks for the tip