Cortex XDR Pro - Looking for Scheduled tasks by name in mass?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Please sign in to see details of an important advisory in our Customer Advisories area.

Cortex XDR Pro - Looking for Scheduled tasks by name in mass?

L4 Transporter

Hello dear community, 

here is a script for searching specific scheduled tasks by name in mass. The search is via LIKE and wildcards are used. 

 

RFeyertag_0-1713736580513.png

 

import subprocess
import sys

def ScheduledTask(scheduler_name):
    # PowerShell-Befehl mit Where-Object und Filterung für den TaskScheduler
    pscommand = f"""Get-ScheduledTask | Where-Object {{$_.TaskName -like '*{scheduler_name}*'}} | ForEach-Object {{ $_.TaskName + "|" + $_.State }}"""
    try:
        # PowerShell-Befehl ausführen und Ausgabe erfassen
        result = subprocess.check_output(["powershell", "& {" + pscommand + "}"], text=True, encoding='utf-8', errors='ignore')
      
        # Ergebnis anzeigen oder weiterverarbeiten
        return result.strip()

    except subprocess.CalledProcessError as e:
        # Fehlerbehandlung, falls der Befehl nicht erfolgreich ist
        sys.stderr.write(f"Fehler bei der Ausführung des Befehls: {e}")
        return None

# Vorherige Festlegung des TaskScheduler-Namens
scheduler_name = "MeinTaskScheduler"

# Aufruf der Funktion mit dem festgelegten TaskScheduler-Namen
output = ScheduledTask(scheduler_name)

# Ausgabe des Ergebnisses ohne Header
print(output)

 

Have fun with it! 

 

BR

 

Rob

1 accepted solution

Accepted Solutions

L4 Transporter

Thanks for sharing!

JM

View solution in original post

2 REPLIES 2

L4 Transporter

Thanks for sharing!

JM

L4 Transporter

You're welcome 🙂

  • 1 accepted solution
  • 710 Views
  • 2 replies
  • 3 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!