1

I need the TaskName and the Status columns displayed from schtasks command.

I tried the following:

for /f "tokens=1,3 delims= " %i in ('schtasks') DO echo %i

The output is not pretty looking. Current output if I run schtasks :

C:\Windows\system32>schtasks
Folder: \Microsoft\Windows\WwanSvc
TaskName                               Next Run Time          Status
NotificationTask                         N/A                    Ready
Folder: \Microsoft\XblGameSave
TaskName                                 Next Run Time          Status
XblGameSaveTask                          N/A                    Ready

Sample desired output:

Folder: \Microsoft\Windows\WwanSvc
TaskName                                      Status
NotificationTask                               Ready
Folder: \Microsoft\XblGameSave
TaskName                                       Status
XblGameSaveTask                                Ready
karel
  • 5,489
  • 46
  • 45
  • 50
jenhenry
  • 23
  • 5
  • 1
    What have you tried and what did you find difficult? Please read the [help] pages and take the [tour] to learn what sort of question can be asked here. – AdrianHHH Jan 19 '21 at 21:16

2 Answers2

1

Whilst it doesn't provide exactly the same output as your desired example, the following, seems usable, (and better), to me:

schtasks /query /fo list | findstr /r "^Folder: ^TaskName: ^Status: ^$"

Which should provide output like this:

Folder: \Microsoft\Windows\WwanSvc
TaskName:      \Microsoft\Windows\WwanSvc\NotificationTask
Status:        Ready

Folder: \Microsoft\XblGameSave
TaskName:      \Microsoft\XblGameSave\XblGameSaveTask
Status:        Ready

BTW, I'm unsure what version of Windows you're intending this for, but certainly from Windows Vista, through to Windows 10, this is the output format I'm used to seeing from schtasks:

Folder: \Microsoft\Windows\WwanSvc
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
NotificationTask                         N/A                    Ready

Folder: \Microsoft\XblGameSave
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
XblGameSaveTask                          N/A                    Ready

Which means that your output, from your provided code, would look like this:

Folder:
TaskName
========================================
NotificationTask
Folder:
TaskName
========================================
XblGameSaveTask

That also means to get the output you desire, you'd need to omit the table header borders, as well as the second table column.


Given that, here's a rather OTT method of potentially achieving that from a :

@Echo Off & SetLocal EnableExtensions DisableDelayedExpansion
Set "{=                                          "
For /F "Delims=" %%G In ('%SystemRoot%\System32\schtasks.exe /Query ^
 ^| %SystemRoot%\System32\findstr.exe /R "^[^=]"') Do (Set "}=%%G"
    SetLocal EnableDelayedExpansion & Set "}=!}:  =|!"
    For /F "Tokens=1,3 Delims=|" %%H In ("!}:| =||!") Do If "%%I" == "" (
        Echo %%H) Else Set "z=%%H%{%" & Echo=!z:~,41!%%I
    EndLocal)
Pause

This should output this for you:

Folder: \Microsoft\Windows\WwanSvc
TaskName                                 Status
NotificationTask                         Ready
Folder: \Microsoft\XblGameSave
TaskName                                 Status
XblGameSaveTask                          Ready
Compo
  • 36,585
  • 5
  • 27
  • 39
0

Pretty easy with PowerShell.

Get-ScheduledTask | Select-Object -Property TaskPath,TaskName,State | Format-List *

If you are not able to run a PowerShell console, you can do it from cmd.exe.

powershell -NoLogo -NoProfile -Command ^
    "Get-ScheduledTask | Select-Object -Property TaskPath,TaskName,State | Format-List *"
lit
  • 14,456
  • 10
  • 65
  • 119