problem of comparating 2 boot times.

Welcome Forums General PowerShell Q&A problem of comparating 2 boot times.

Viewing 5 reply threads
  • Author
    Posts
    • #195287
      Participant
      Topics: 1
      Replies: 2
      Points: 16
      Rank: Member

      Hello,

      I’ve a problem with my code, i’m not very specialist of PS, and i think that my problem is from a variable problem.

      I try to compile a PS script that do some tricks if a PC was booted since less than X minutes, and other things if > 7 minutes

      That’s my code:

      I try with 13 minutes and it’s ok:

      “Computer boot since 13 Minutes
      13
      13,4964267466667
      7
      more than 7 min since last boot”

      I try now with 5 minutes, and i don’t knows why, but it doesn’t work:

      “Computer boot since 5 Minutes
      5
      4,81610453666667
      7
      more than 7 min since last boot”

      Anybody have an idea what i’m wrong?

      Thank you for your help

    • #195329
      Participant
      Topics: 10
      Replies: 2481
      Points: 6,543
      Helping Hand
      Rank: Community MVP

      May I suggest a different approach?

      • #195392
        Participant
        Topics: 1
        Replies: 2
        Points: 16
        Rank: Member

        Hi olaf,

         

        Ok, it’s sure, it works with your script! and i will use it to continue my script.

        But, if i want to progress, i want to undestand why my script is bad!

        Thank you.

         

         

    • #195350
      Participant
      Topics: 17
      Replies: 1958
      Points: 4,020
      Helping Hand
      Rank: Community Hero

      How are you planning on executing this script? Understand that you would basically have to run that script on boot and loop continually to see where the to hit the 7 min mark. If you are launching it at boot, why not just do basic sleeps:

      • #195395
        Participant
        Topics: 1
        Replies: 2
        Points: 16
        Rank: Member

        Hello rob,

         

        No it’s the beginning of a script, and i think that it is not the good way, but i’m not good in PS, so i must start with something.

        The idea is that : We will open all computer of our company on a date/hour (for example, sunday) with a bios auto boot config.

        The idea is to lunch, somes minutes after the boot (5 minutes i think), a script that will analyse if the computer is open since 7 minutes.

        The idea is:

         

        • If computer is booted more than 7 minutes : there is a chance that this is a pc that is using by a users : so DO NOTHING
        • If computer is booted less thant 7 minutes : the pc just booted up, so  we do some tricks (update, antivirus, cleaning script, and finally, shutdown).

         

    • #195512
      Participant
      Topics: 8
      Replies: 9
      Points: 158
      Rank: Participant

      I have a dump question.

      Message = “This computer is up for {0} days, {1} hours, {2} minutes and {3} seconds.” -f $Uptime.Days, $Uptime.Hours, $Uptime.Minutes, $Uptime.Seconds

      What is “-f” for ? Any reference that I can look at

    • #195530
      Moderator
      Topics: 5
      Replies: 245
      Points: 1,394
      Helping Hand
      Rank: Community Hero

      It is formating the strings using placeholders, and please refer to this link below…

      https://ss64.com/ps/syntax-f-operator.html

    • #195692
      Participant
      Topics: 8
      Replies: 9
      Points: 158
      Rank: Participant

      Thanks a lot.

Viewing 5 reply threads
  • The topic ‘problem of comparating 2 boot times.’ is closed to new replies.