Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Contact
  • Reviews
  • Toggle search form
Home » Windows » Run Python Script via Windows Task Scheduler
  • Protecting DS923 NAS
    DSM Security: How to Protect Synology DS923+ NAS Reviews
  • Compacting VHD
    How to Compact Virtual Hard Disks on VMware Virtualization
  • image 23
    Copy Deployment Share between Servers without using linked Deployment Shares Windows
  • ddf
    How to configure Windows Deployment Services on Windows Server Windows Server
  • fhgj
    Resolve DISM unspecified error when removing preinstalled packages(Error code 15601) Windows Server
  • Featured image 1
    Transfer Windows License from one PC to the other on Windows Windows
  • Integrate WordTune on Microsft Word
    Integrate WordTune with Microsoft Word on Mac Microsoft Exchange/Office/365
  • fddd
    How to check the version of Windows ADK Windows

Run Python Script via Windows Task Scheduler

Posted on 07/02/202314/05/2025 Christian By Christian No Comments on Run Python Script via Windows Task Scheduler
schedulepythontasksinWindows

In this article, you will learn how to determine the number of MBAM Recoveries Performed, and how to run Python Script via Windows Task Scheduler. Windows Task Scheduler enables you to perform routine tasks in Windows on individual PCs. Task Scheduler does this by monitoring whatever criteria you choose. This is referred to as “triggers” and then executing the tasks when those criteria are met. You can use the Task Scheduler to execute tasks such as starting an application, Wbadmin Email Alerts: Sending an email message, etc.

Note: This article on Python Automation in Windows with Visual Studio Code is a prerequisite for running Python Script via Windows Task Scheduler

Tasks can be scheduled to execute in response to these events, or triggers. If you wish to have your script run at a specified period of time or a specific number of times in Windows, you will have to create a scheduled task.

Also, see “How to Fix Python was not found run without arguments to install from the Microsoft Store“, and how to “Add Dynamic Wallpaper controlled by time on Windows 10 and 11“.

What is MBAM?

Before discussing the steps to run a Windows Scheduled Task. I will like to discuss what Microsoft BitLocker Administration and Monitoring (MBAM) is. It is an administrator interface used to manage BitLocker drive encryption. It allows you to configure your enterprise with the correct BitLocker encryption policy options, as well as monitor compliance with these policies.

Kindly refer to the following similar guides on BitLocker. how to fix the missing BitLocker Recovery Tab in Active Directory Users and Computers, and how to enable or disable BitLocker Drive Encryption on Windows 10 and Virtual Machines.

How to run Python Script via Windows Task Scheduler

In Linux, you will have to create a cron job. The cron command-line utility is a task (job) scheduler on Unix-like operating systems. Using Windows Scheduler is most suitable for scheduling repetitive tasks.

Here are some related topics: How to automate Windows Update with PowerShell and Task Scheduler, Task scheduler errors, and success code |What does code 0x41301 mean?, how to create, edit and delete a scheduled task via the Command Prompt, and Windows Admin Center Error: Scheduled task status prompts error 0x800710E0.

Since I do not want to manually run this task, once a week, twice a month, every week, etc., as the case may be for you, Windows provides a tool that will run our script at a given time. These tasks can be created to execute in response to these events or triggers in the Windows Task Scheduler.

Prepare the Python Script

You would need to have a Python script ready in order to perform this operation successfully. Here is a sample script used for determining the “number of BitLocker key recovery operations with Successful status in the last two weeks When you are finished with the Python script, ensure you have it saved with the .py extension to any location of your choice “C:\Users\techdauser1\test1.py“.

For me, I have it saved to the desktop as this is just for demonstration solely for writing this guide. This code assumes you already have the CSV file imported from the MBAM Reporting Services.

Note: I will be configuring Windows Task Scheduler to run a Python script via PowerShell. Using the using a wrapper .ps1 PowerShell script is absolutely an easy approach to run Python scripts in PowerShell. Ensure sure Python is installed and in the system PATH. Also, do not forget to set the PowerShell execution policy to bypass the file in the argument ‘-ExecutionPolicy Bypass -File “C:\Path\To\Your\ScriptRunner.ps1” for example if you wish to use this approach or outrightly, permit PowerShell to run. Alternatively, you could also use the .bat wrapper, but this will not be covered in this post.

Here are some guides on how to do this “Recovery Audit Report: How to query MBAM to display the report for BitLocker Recovery for a specified period of time“, and “MBAM reports automatic E-mail notification: How to create MBAM Enterprise and Compliance, and Recovery Audit reports“.

#script created by Christian Eromosele. If you must use it on any blog, kindly ensure you reference the link to the blogpost.
import csv
import datetime
# Get the current date and time
current_date = datetime.datetime.now()
# Calculate the date two weeks ago
two_weeks_ago = current_date - datetime.timedelta(weeks=2)
# Open the CSV file
with open("C:\\Users\\TechDAPC1\\Desktop\\RecoveryAudit\Recovery Audit Report.csv", 'r') as file:
    reader = csv.reader(file)
    # Skip the header row
    next(reader)
    # Count the number of success events
    success_count = 0
    for row in reader:
        event_date = datetime.datetime.strptime(row[0], '%m/%d/%Y %H:%M:%S %p')
        if event_date >= two_weeks_ago and row[2] == "Successful":
            success_count += 1/2
# Print the number of success events
print("Number of BitLocker key recovery operations with status "Successful" in the last two weeks: ", success_count)
#used to exit or terminate a script after execution completes
exit ()

Steps to set up the Windows Task Scheduler to run Python Script

These steps are similar to running PowerShell or bask scripts. Since this article is on Python script execution, kindly let’s jump at it right away.

Launch the task scheduler: To do this, open the task scheduler application on your computer by searching for Task Scheduler in the start menu.

image-21

Alternatively, to bring up the Run dialogue box, press its Win + R key combination. Next, enter taskschd.msc within the run dialog window.

image-22

Click the OK button to open the Task Scheduler window. This will open the Task Scheduler window.

image-23

Note: There are tons of ways to open Windows Task Scheduler such as from the Windows terminal, Computer Management console, Task Manager, Control Panel, or by creating a Task Scheduler Shortcut on your desktop etc. You just have to decide on any of the methods here that are favourable to you.

Please see how to visualize MBAM Recovery Audit Report with Python, how to Run or Edit and Delete Tasks via Windows Task Scheduler, Ansible: No Python interpreters found for the host, how to detect if an application was uninstalled on Windows: Find out who has uninstalled an application via Windows Event Viewer, and how to create and set up Azure Container Instance to deploy your first Docker Image to Azure Using Azure CLI.

Create a New Task: To create a task in the task, click on create Task as shown below.

Create a Windows Scheduler Task

Determine the Path to your Python Installation

Note: There are different ways to run Python script in Windows such as creating a batch file to run Python script or using an executable (exe) where the path of our Python installation will be required.

To run the Python script automatically using the Windows scheduler, kindly follow these steps attentively. You will need the path to the Python installation such as

C:\Users\techdauser1\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_xxxxxx\python.exe”. 

Since I installed Python via the Microsoft store, this was handled by Microsoft for me. You may need to run the following python code below to determine the path to your python installation.

For more information on this, please see “Getting started with Python Automation in Windows with Visual Studio Code“, and how to upgrade and downgrade PIP on Windows.

import sys
print(sys.executable)
image-25

Below is the output when the code above is run.

image-26

You could also determine the python installation path via the Python interactive Shell as shown below. In this case, Python was not installed from the Microsoft store.

image-27

Run the Python Script via Task Scheduler

Now that we have the python installation path, we should then proceed with creating the scheduled task. Under the “Create Task” window, enter your desired name as shown below.

Select Run whether user is logged on or not.
Select Run with highest privileges option. Shortly, I will select the option "Do not store password".
image-28

Under Security Options, identify the domain/Windows account currently associated with the task. If it is not the correct account, click Change User or Group and select the right account.

Navigate to the next Tab “Triggers”. Click on New

image-29

This would open the New trigger window. The options here are left to you and should be configured based on your lab, Test or production requirements.

Define Triggers

As you can see below, I have configured the Trigger and will now move to the next Tab.

By the way, a trigger means an event that causes our script to run.
Task scheduler triggers Tab

On the Actions Tab, click on New as shown below.

Task scheduler Actions Tab
image-33

Define the Action

As you can see above, we do not have any arguments and programs yet. Please specify the following parameters as shown in the image below:

  • Action: Start a program
  • Program\script: [Exe name or paths like Python.exe or cmd.exe or PowerShell location]. In our case, it is Python.
  • Add arguments (optional): [Add command line argument if any] – Path to the python script itself.
  • Start in(optional): [directory path where python script exists]

If these parameters are not entered correctly, you would get the following errors “how to fix 0x2 task scheduler“, and “how to fix the directory name is invalid“.

image-34

As you can see, the Action task has been created.

image-35

Alternatively, you could specific the arguments and start in this way which is my preferred choice.

Argument and start in option
Note: If you are running the Python script under a different user account (e.g., via Task Scheduler or a service account), ensure that the correct Python interpreter from the shared environment is being used. If the script references a Python installation that is not accessible or not properly configured for that user, it may fail with a 0x2 (File not found) error. This occurs when the specified path to the Python executable or script is invalid or the environment variables are not set for the target user.

Uncheck any connection that is not applicable to you

image-36

Under the settings Tab, kindly specify the settings that you would like to affect the behaviour of your task.

image-37

Enter your Credential in the Task Scheduler Window

Upon clicking on OK, you will be prompted to enter your password. Kindly enter your password and press OK.

image-38

Note: If you remember above, I told you how to use the option “Do not store password”. Head back to the General Tab by editing your Task as shown below.

Check the button "Do not store password. The task will only have access to the local computer resources" and click on Ok..
Run Windows Task scheduler without storing the password

As you can see below, we have successfully created our task in Windows. As you can see, the task is Ready and has not been run yet.

image-40

Therefore, we will manually run it by right-clicking on the Task “Test-Rule1” and selecting “run“. Or click on the task and select run on the Action pane.

image-41

View Scheduled Task Job

As you can see below, I have manually run the task to ensure it is free of errors and will be run as scheduled. If you no longer need this task, you can have it disabled.

At this point, you can close the Windows Task Scheduler. You are free to learn more about Python in Windows from this link. Also, here is an interesting link on Python on Windows from Microsoft.

image-42

You could also take a look at the Windows Event Log for the successful completion of this task. Here is how to locate it.

Task Scheuler Event Log
Task Scheduler Event Log

I hope you found this blog post helpful. Now, you have learned how to determine the number of MBAM Recoveries Performed: How to run Python Script via Windows Task Scheduler. Please let me know in the comment session if you have any questions.

5/5 - (1 vote)

Thank you for reading this post. Kindly share it with others.

  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on Threads (Opens in new window) Threads
  • Click to share on Nextdoor (Opens in new window) Nextdoor
Windows, Windows Server Tags:Bitlocker, BitLocker Recovery Keys, BitLocker Status, MBAM, MBAM Reports, Microsoft Windows, Python, recovery, Windows 10, Windows 11, Windows Server 2016

Post navigation

Previous Post: Set Two-Factor Authentication for SSH in Linux
Next Post: How to Allocate, Associate, Disassociate and Release Elastic IP Address from an EC2 Instance

Related Posts

  • vmware
    Windows Startup Error: VMware Status 0xc000014c – Missing Boot Data Windows
  • screenshot 2020 02 07 at 21.59.33
    Prerequisites for setting up a Single and Multi App Kiosk Windows
  • dfggg 1
    Configuring SimpleSAMLPHP Windows Server
  • remote desktop connection 5 1280x720 1
    How to view and remove Remote Desktop connection history Windows
  • Featured image   This network connection does not exist
    How to fix this network connection does not exist Windows
  • showdefenderupdate
    View Microsoft Defender Antivirus Update Details on Windows Image Windows

More Related Articles

vmware Windows Startup Error: VMware Status 0xc000014c – Missing Boot Data Windows
screenshot 2020 02 07 at 21.59.33 Prerequisites for setting up a Single and Multi App Kiosk Windows
dfggg 1 Configuring SimpleSAMLPHP Windows Server
remote desktop connection 5 1280x720 1 How to view and remove Remote Desktop connection history Windows
Featured image   This network connection does not exist How to fix this network connection does not exist Windows
showdefenderupdate View Microsoft Defender Antivirus Update Details on Windows Image Windows

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • Protecting DS923 NAS
    DSM Security: How to Protect Synology DS923+ NAS Reviews
  • Compacting VHD
    How to Compact Virtual Hard Disks on VMware Virtualization
  • image 23
    Copy Deployment Share between Servers without using linked Deployment Shares Windows
  • ddf
    How to configure Windows Deployment Services on Windows Server Windows Server
  • fhgj
    Resolve DISM unspecified error when removing preinstalled packages(Error code 15601) Windows Server
  • Featured image 1
    Transfer Windows License from one PC to the other on Windows Windows
  • Integrate WordTune on Microsft Word
    Integrate WordTune with Microsoft Word on Mac Microsoft Exchange/Office/365
  • fddd
    How to check the version of Windows ADK Windows

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,839 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.