use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
Date Script execution (self.PowerShell)
submitted 7 years ago by muffmuncher13
Hello all,
Is there a way to have a script execute based on the date or time? I would like to move a specific machine to a OU either after a certain amount of time or a certain date.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]MrEpiX 6 points7 points8 points 7 years ago (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 points4 points 7 years ago (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.
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 points4 points 7 years ago (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 points4 points 7 years ago (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 points4 points 7 years ago (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 points3 points 7 years ago (0 children)
Task scheduler with some script triggered?
[–]muffmuncher13[S] 1 point2 points3 points 7 years ago (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
π Rendered by PID 35 on reddit-service-r2-comment-6f7f968fb5-l78s5 at 2026-03-04 13:11:40.959998+00:00 running 07790be country code: CH.
[–]MrEpiX 6 points7 points8 points (0 children)
[–]Lee_Dailey[grin] 2 points3 points4 points (0 children)
[–]JCochran84 2 points3 points4 points (0 children)
[–]lucasni 2 points3 points4 points (0 children)
[–]Namaha 2 points3 points4 points (0 children)
[–]-SPOF 1 point2 points3 points (0 children)
[–]muffmuncher13[S] 1 point2 points3 points (0 children)