Saturday, September 29

Query Scheduled Task

Recently I was required to audit a mix of Citrix farms for all scheduled task & find service accounts if was used any. I found this script after googling that helped me complete my task:
-------------------------------------------------------------------------------------------------------------------
@echo off
 
:: delete results.csv
del results.csv

for /f %%a in ('type Computers.txt') do (
If Exist results.csv (
echo Processing %%~a
echo Processing %%~a >> results.csv
schtasks.exe /Query /S %%~a /FO CSV /NH /V >> results.csv
) Else (
Rem CREATE Headers (note /NH switch has been removed) - headers will opnly be created if the first server in your list has a scheduled task)
echo Processing %%~a
echo Processing %%~a >> results.csv
schtasks.exe /Query /S %%~a /FO CSV /V >> results.csv
Set HeadersCreate = "done"
)
     
)
echo Done.
-----------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment