- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
04-21-2024 03:02 PM
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.
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
04-23-2024 12:00 PM
Thanks for sharing!
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!