How to deal with Windows Schedule&Task by PowerShell in Win7

 

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

$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

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值