简体   繁体   中英

How to get list of folders from Schedule.Service in powershell

I have a powershell script that lists the tasks in the root folder of task scheduler.

I can hard code sub folders, but I would like to be able to query the sub folders so it will work when new folders are added. Can this be done and, if so, how?

The relevant bit of script showing hard coded sub folder "Reports" being accessed:

$sch = New-Object -ComObject("Schedule.Service")
...
$tasks = $sch.GetFolder("\Reports").GetTasks(0)
$tasks | ForEach-Object{
...

Never mind - figured it out:

$root = $sch.GetFolder("\")
$subfolders = $root.GetFolders(0)
$subfolders | foreach-object{
  $tasks = $_.GetTasks(0)
  ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM