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 batch-file:
@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