| Richard's profileRichard Siddaway's BlogPhotosBlogLists | Help |
|
November 12 Cleaning the Temp folder - SchedulingWhen I posted about cleaning the temp folder http://msmvps.com/blogs/richardsiddaway/archive/2009/11/04/cleaning-temp-folder.aspx I said I would look at scheduling the task. I had intended to use the TaskScheduler module in the new PowerShell pack which can be downloaded from http://code.msdn.microsoft.com/PowerShellPack. It is also available in the Windows 7 Resource Kit. The pack provides 10 modules for PowerShell 2.0 covering a number of areas: DotNet The modules are installed in WindowsPowerShell\Modules in your profile. I’ll look at some of the others in future posts but for now I want to concentrate on the Scheduler. The module supplies a number of functions Add-TaskAction I had difficulty with the Add-TaskAction and Add-TaskTrigger functions so I ended up experimenting and produced the following script
I imported the TaskScheduler module and used the New-Task function to create a task. I then set the task to run every day at 1:00pm. The action the task performs is to first start PowerShell in the present working directory. Create a script block to run and encode it as shown. The two references to $task show me the contents of the task variable. its worth a look especially the XML. Connect-TaskScheduler is used to create a variable I can use for scheduling the task. We can see the scheduled task using Get-ScheduledTask We can run the task outside of the scheduled time PS> Get-ScheduledTask -Name TempClean | Start-Task Name : TempClean And we can remove the task Get-ScheduledTask -Name TempClean | Remove-Task the task scheduler API is documented on MSDN. http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx This holds a lot of possibilities including creating tasks on remote machines. Needs more investigation especially why the functions aren’t working for me. TrackbacksThe trackback URL for this entry is: http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2605.trak Weblogs that reference this entry
|
|
|