ToShortTimeString() vs .Converttodatetime( )

This topic contains 7 replies, has 3 voices, and was last updated by  H Man 4 years ago.

  • Author
  • #16647

    H Man

    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

  • #16648

    H Man

    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 $;$i++) {
      $class = $html.CreateAttribute("class")
      #check the value of the last column and assign a class to the row
      if (($[$i].td[-1] -as [datetime]) -notlike '*11:00*') {                                          
        $class.value = "danger"  
        $[$i].Attributes.Append($class) | Out-Null
  • #16649

    H Man

    not sure if my conditional statement is on point

  • #16650

    H Man

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

  • #16651

    Dave Wyatt

    You should be able to do this:

  • #16652

    H Man

    thanks again Dave! really appreciate your help today

  • #16653

    Don Jones

    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.

  • #16654

    H Man

    ok Don Will do ! and thanks for the tip

You must be logged in to reply to this topic.