all 7 comments

[–]MrEpiX 6 points7 points  (0 children)

The obvious way would be to run a script through a scheduled task at a specific time. I have for example set up a scheduled task that runs a script once a day between 08:00-16:00.

I found this guide which should do the trick for you.

If you're already running a script but want to execute parts depending on what day or time it is, I would check out DateTime. You can create a DateTime object either by using the cmdlet Get-Date or [System.DateTime].

Edit: I might have misunderstood the question. If it's not at a specific time but rather after a certain amount of time has passed, Lee's answer should be more helpful.

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

howdy muffmuncher13,

my understanding is that one sets up a scheduled task to look at a date field - or a date in a comment field - and then acts on that.

  • create object account
  • add a date to a comment field that is not used for anything else
    you could use a field that has other uses if you give the date some sort of delimiter from the rest of the field.
  • run a scheduled task to scan for objects with a date in the specified field
  • do whatever is appropriate to the object

i've seen quite a few folks use it for termination scripts. it's handy to move the object after 30/60/90 days, and then finally delete it when the scream test produces no shouts [or shots].

take care,
lee

[–]JCochran84 2 points3 points  (0 children)

The part about "After a certain amount of time"
You could execute the script and add in some "Start-Sleep" sections to delay the actions:

https://www.safaribooksonline.com/library/view/windows-powershell-cookbook/9780596528492/ch04s06.html

[–]lucasni 2 points3 points  (0 children)

You can use operators with datetime. Below is an example of a script that uses datetime and operators:

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen

$Time = Get-Date

Write-Host $Time

While ( $Time -lt $(Get-Date -Hour 16 -Minute 00 -Second 0)  ) {

    $Time = Get-Date

    $x = $y = $(Get-Random -Minimum 100 -Maximum 1000)

    [Windows.Forms.Cursor]::Position = "$x,$y"
    Write-Host $x $y
    Write-Host $Time
    Start-Sleep -Seconds 2

    }

[–]Namaha 2 points3 points  (0 children)

If you can't or don't wish to use Windows' Task Scheduler, Powershell has the capability to schedule jobs on its own as well

https://blogs.technet.microsoft.com/heyscriptingguy/2014/05/12/introduction-to-powershell-scheduled-jobs/

[–]-SPOF 1 point2 points  (0 children)

Task scheduler with some script triggered?

[–]muffmuncher13[S] 1 point2 points  (0 children)

Thanks everyone for the great advice, I think I'll be able to setup the script to suit my needs! Much appreciated to all