Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - FWIW - Scheduleded Tasks

Reply
 
Old 08-31-2007   #1 (permalink)
Rob Campbell
Guest


 
 

FWIW - Scheduleded Tasks

Here's a script to gather the scheduled task information from a collection of
computers:

remove-item sch_tasks.csv

$headings = '"HostName","TaskName","Next Run Time","Status","Last Run
Time","Last Result","Creator","Schedule","Task To Run","Start
In","Comment","Scheduled Task State","Scheduled Type","Start Time","Start
Date","End Date","Days","Months","Run As User","Delete Task If Not
Rescheduled","Stop Task If Runs X Hours and X Mins","Repeat: Every","Repeat:
Until: Time","Repeat: Until: Duration","Repeat: Stop If Still Running","Idle
Time","Power Management"'

ac sch_tasks.csv $headings

foreach ($computer in $computers){
$task_query = schtasks /query /fo csv /v /s $computer

if ($task_query.count -ge 2){
for ($i=1;$i -le $task_query.count;$i++){
if ($task_query[$i] -notmatch "$headings"){
ac sch_tasks.csv $task_query[$i]
}
}

$tasks_found = import-csv sch_tasks.csv

$tasks_found |% {
$out_file = $_.hostname + "+" + $_.taskname + ".clixml"
export-clixml -path $out_file -inputobject $_}
}
}

It uses the schtasks command to get the task information, and creates PS
objects for each task, with the properties named as returned by the command.

Some of them have embedded spaces, so they need to be enclosed in quotes

eg $task."next run time"

Gathering all the task information can be an expensive proposition, so the
collected information is saved both as a .csv file and clixml files for each
task. The clixml files are name as hostname + taskname.clixml. The can be
retrieved individually as objects by doing an import-clixml on the file.

Right now, it basically just good for reporting.

It wouldn't be too hard to be able to have Run, End, and Delete functions
since these only require the host name and task name as parameters. Not sure
right now if I want to implement those as script functions or object methods.

Changing the properties of the objects and sending that back through
schtasks to update the scheduled tasks is going to be more complicated.

I'm thinking I may want to alias some of those properties to something a
little "friendlier", too.

Thoughts/comments welcome.


My System SpecsSystem Spec
Old 08-31-2007   #2 (permalink)
Oisin Grehan
Guest


 
 

Re: FWIW - Scheduleded Tasks

On Aug 31, 12:10 pm, Rob Campbell
<RobCampb...@xxxxxx> wrote:
Quote:

> Here's a script to gather the scheduled task information from a collection of
> computers:
>
> remove-item sch_tasks.csv
>
> $headings = '"HostName","TaskName","Next Run Time","Status","Last Run
> Time","Last Result","Creator","Schedule","Task To Run","Start
> In","Comment","Scheduled Task State","Scheduled Type","Start Time","Start
> Date","End Date","Days","Months","Run As User","Delete Task If Not
> Rescheduled","Stop Task If Runs X Hours and X Mins","Repeat: Every","Repeat:
> Until: Time","Repeat: Until: Duration","Repeat: Stop If Still Running","Idle
> Time","Power Management"'
>
> ac sch_tasks.csv $headings
>
> foreach ($computer in $computers){
> $task_query = schtasks /query /fo csv /v /s $computer
>
> if ($task_query.count -ge 2){
> for ($i=1;$i -le $task_query.count;$i++){
> if ($task_query[$i] -notmatch "$headings"){
> ac sch_tasks.csv $task_query[$i]
> }
> }
>
> $tasks_found = import-csv sch_tasks.csv
>
> $tasks_found |% {
> $out_file = $_.hostname + "+" + $_.taskname + ".clixml"
> export-clixml -path $out_file -inputobject $_}
>
> }
> }
>
> It uses the schtasks command to get the task information, and creates PS
> objects for each task, with the properties named as returned by the command.
>
> Some of them have embedded spaces, so they need to be enclosed in quotes
>
> eg $task."next run time"
>
> Gathering all the task information can be an expensive proposition, so the
> collected information is saved both as a .csv file and clixml files for each
> task. The clixml files are name as hostname + taskname.clixml. The can be
> retrieved individually as objects by doing an import-clixml on the file.
>
> Right now, it basically just good for reporting.
>
> It wouldn't be too hard to be able to have Run, End, and Delete functions
> since these only require the host name and task name as parameters. Not sure
> right now if I want to implement those as script functions or object methods.
>
> Changing the properties of the objects and sending that back through
> schtasks to update the scheduled tasks is going to be more complicated.
>
> I'm thinking I may want to alias some of those properties to something a
> little "friendlier", too.
>
> Thoughts/comments welcome.
Good post Rob, thanks!

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
WLM Tasks Live Mail
Tasks Vista mail
Why do i get tasks that i know nothing about?? VB Script
Drowning in Tasks - Help? Vista General
ReadyBoost? ... just a FWIW Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46