Lista de scripts em lote Todos os nomes e comandos de tarefas do Agendador de tarefas
Eu forneci um script em lote abaixo que será executado a partir do Windows 7 e do Windows 10 .
Essentially this will:
- Run schtasks with the
/XML
switch and pipe all the XML content it reads through the findstr command with theI
switch (case insensitive) filtering it to only redirect the lines that contain the<!--
and<command>
strings as ouput to a flat file.- The flat file content is then run through a dynamic PowerShell script that will replace the XML tags with more appropriately formatted field names, trim any leading white space from all lines, remove all blank line, and lastly put a new line before each of the
Task Name
fields but it'll skip the first line as it won't need to have a line before it—the topmost line in the file.Note: See the Gotchas section below for potential anomaly detail and items to note.
O script em lote
@ECHO ON
SET RptFile=%temp%\TaskSchedReport.txt
:: -- This routine sets temp files
SET RptFileTmp=%temp%\~tmpTaskSchedReport.txt
IF EXIST "%RptFileTmp%" DEL /Q /F "%RptFileTmp%"
SET TmpPSScript=%Temp%\~tmpScheduleTasks.ps1
IF EXIST "%TmpPSScript%" DEL /Q /F "%TmpPSScript%"
:SchTask
schtasks /query /XML | Findstr /I "<!-- <command>">"%RptFileTmp%"
:PowerShell
ECHO $origFile = "%RptFileTmp%" >> "%TmpPSScript%"
ECHO $NewFile = "%RptFile%" >> "%TmpPSScript%"
ECHO $BlankLine = "'r'n" >> "%TmpPSScript%"
ECHO (Get-Content $origFile) ^| Foreach-Object { >> "%TmpPSScript%"
ECHO $_ -replace "<!-- ", 'Task Name (and path): ' -replace "<Command>", 'Command: ' -replace "<[^>]+>", '' -replace '^^\s+', '' -replace '(?m)^^\s*\r?\n', ''>> "%TmpPSScript%"
ECHO } ^| Set-Content $NewFile >> "%TmpPSScript%"
ECHO (Get-Content $NewFile) ^| ? {$_.trim() -ne "" } ^| Set-Content $NewFile >> "%TmpPSScript%"
ECHO (Get-Content $NewFile) ^| Foreach-Object { >> "%TmpPSScript%"
ECHO $_ -replace "Task Name ", ($BlankLine + "Task Name ") -replace "-->", '' >> "%TmpPSScript%"
ECHO } ^| Set-Content $NewFile >> "%TmpPSScript%"
ECHO (Get-Content $NewFile ^| Select-Object -Skip 1) ^| Set-Content $NewFile >> "%TmpPSScript%"
SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
CD /D "%PowerShellDir%"
Powershell -ExecutionPolicy Bypass -Command "& '%TmpPSScript%'"
:: -- Below will open file to view content with the default text editor
explorer.exe "%RptFile%"
Resultados
Task Name (and path): \Adobe Acrobat Update Task
Command: C:\Program Files\Common Files\Adobe\ARM.0\AdobeARM.exe
Task Name (and path): \GoogleUpdateTaskMachineCore
Command: C:\Program Files\Google\Update\GoogleUpdate.exe
Task Name (and path): \GoogleUpdateTaskMachineUA
Command: C:\Program Files\Google\Update\GoogleUpdate.exe
Task Name (and path): \TopSecret
Command: C:\Folder\CIA.exe
Command: C:\Folder\FBI.exe
Pegadinhas
Se você observar um item de campo Task Name
sem nenhum item de campo Command
abaixo, isso parece ser devido a tarefas agendadas do sistema etc. que têm Actions
listado como Custom Handler
valores que não podem ser editados. exemplos e captura de tela abaixo.
Exemplo (sem comandos)
Task Name (and path): \Microsoft\Windows\Shell\WindowsParentalControls
Task Name (and path): \Microsoft\Windows\Shell\WindowsParentalControlsMigration
Task Name (and path): \Microsoft\Windows\SideShow\AutoWake
Task Name (and path): \Microsoft\Windows\SideShow\GadgetManager
Task Name (and path): \Microsoft\Windows\SideShow\SessionAgent
Task Name (and path): \Microsoft\Windows\SideShow\SystemDataProviders
Configurações do Job Scheduler Job (sem comandos / ações)