It only will work on Vista/2008 & up, please don't run it on XP/2003.
If you have to deal with the Schedule&Task on the XP/2003, please refer to the http://code.google.com/p/subsoniccms/source/browse/trunk/TaskScheduler/?r=21
The following resolution will running on Vista/2008 & up.
1.New a COM object with "Schedule.Service"
$scheduleTask = New-Object -ComObject "Schedule.Service"
2.Connect to local computer. You also can type remote computer name.
$scheduleTask . Connect ( "localhost" )
3.Get the folder by the specified path.If you want to get the root folder in the Scheduler&Task, the $workingDirectory will be "\".
$rootFolder = $scheduleTask . GetFolder ( $workingDirectory )
4.Get the task by the task name from the folder specified in the Step 3.
$targetTask = $rootFolder . GetTasks (0) | Where-Object { $_ . name -eq $name }
5.Get the xml property from task object.
[ xml ] $xml = $targetTask . xml
6.Get the logon account.
$principal = $xml . Task . Principals
If you have to deal with the Schedule&Task on the XP/2003, please refer to the http://code.google.com/p/subsoniccms/source/browse/trunk/TaskScheduler/?r=21
The following resolution will running on Vista/2008 & up.
1.New a COM object with "Schedule.Service"
$scheduleTask = New-Object -ComObject "Schedule.Service"
2.Connect to local computer. You also can type remote computer name.
$scheduleTask . Connect ( "localhost" )
3.Get the folder by the specified path.If you want to get the root folder in the Scheduler&Task, the $workingDirectory will be "\".
$rootFolder = $scheduleTask . GetFolder ( $workingDirectory )
4.Get the task by the task name from the folder specified in the Step 3.
$targetTask = $rootFolder . GetTasks (0) | Where-Object { $_ . name -eq $name }
5.Get the xml property from task object.
[ xml ] $xml = $targetTask . xml
6.Get the logon account.
$principal = $xml . Task . Principals
$actualLogonAccount=$principal.Principal.UserId
7.Get the frequency array.
$triggers=$xml.Task.Triggers
$calendarTriggers=$triggers.CalendarTrigger
$actualFrequency= @()
foreach($calendarTriggerin$calendarTriggers)
{
$actualFrequency+=$calendarTrigger.LastChild.Name
}
8.Get the commands array.
$actions=$xml.Task.Actions
$execs=$actions.Exec
$actualCommands= @()
foreach($execin$execs)
{
$actualCommands+=$exec.Command
}