Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Nov 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Run script if start time in PowerShell

    Hello,

    I very new to powershell and i need help to achive this.

    At one stage of my poweshell script i want to define that if start time is 11:40 P.M. then hold this running script till 12:01 A.M. Suppose if its before 11:40 P.M. continue the script or if its past 12:01 A.M. then also continue, but if time is 11:40 hold on till 12:01A.M and then continue. Time / clock of local machine.

    Desperately needs help.
    Thanking in advance.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Gold Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,383
    Thanks
    7
    Thanked 205 Times in 195 Posts

  4. #3
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    5,832
    Thanks
    186
    Thanked 706 Times in 644 Posts
    Carmine,

    This code works in my tests.
    Code:
    $TrigerHr = 23
    $TriggerMin = 39
    
    $CurDT = Get-Date
    $CurHr = $CurDT.Hour
    $CurMin = $CurDT.Minute
    
    if ( $CurHr -eq $TrigerHr -and $CurMin -gt $TriggerMin ) { 
      Write-Host "Sleeping"
      #Note: Subtracting from 61 so you get 12:01 AM for restart!
      $Delay = (61 - $CurMin) * 60 #Calculates sleep based on current time.
      Start-Sleep -Seconds $Delay
    }
    
    #Continue here
    HTH
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  5. The Following User Says Thank You to RetiredGeek For This Useful Post:

    carmine (2014-03-25)

  6. #4
    New Lounger
    Join Date
    Nov 2013
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks Paul T.
    Thanks R.G. Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •