# Create a PowerShell scheduled task

Review the Windows Task Scheduler setup recorded for a PowerShell 7 task. The source warns that the Windows Store installation of pwsh.exe did not work for its scheduled tasks.

!!!warning Source-derived reference
These notes were recovered from OneNote. Configuration, permissions and operating results have not been freshly verified. Confirm the applicable authority and environment before acting.
!!!

**Author:** Jason Treadwell

The source uses PowerShell 7 (`pwsh.exe`) for its scheduled tasks.

**WARNING**: If pwsh.exe has been installed via the MS Windows App Store, the pwsh.exe will not run.

## Task Scheduler

### Create Powershell folder for your tasks

Open "Task Scheduler" (taskschd.msc) Right Click on "Task Scheduler Library" Select "New Folder" Type in Powershell and press the **Ok** button

[Screenshot retained for review](../../review/Review-status.md#asset-e4765ea2b77741eacdaf)

### Create Basic Task

Right click the Powershell Folder and select Create Basic Task...

[Screenshot retained for review](../../review/Review-status.md#asset-3b6b0b2955824aff3f86)

#### Set Task Name and Description

**Task Name:** **NOTE** After the Name is set you can't change it without exporting the task, importing the task, deleting the old task. The captured example is named "M365 Company Devices By School Best Effort"

[Screenshot retained for review](../../review/Review-status.md#asset-a1aef63b5689a857871e)

**Task Description:** The source puts the function name, `Get-CompanyDevicesBySchoolBestEffort`, in the description so it is visible when selecting the task.

Example of what you see when you click on a task in Task Scheduler

[Screenshot retained for review](../../review/Review-status.md#asset-eb037950883555393a2a)

**Click** **NEXT**

#### Set Trigger

Set trigger to **Weekly**

Click **Next**

[Screenshot retained for review](../../review/Review-status.md#asset-c91c4ba10c9a7d9bdbf0)

**Select Days and Start Time**

Click **Next**

[Screenshot retained for review](../../review/Review-status.md#asset-2d6465a3942a4db2d28e)

**Select Start a program** (should be selected by default) Click **Next**

[Screenshot retained for review](../../review/Review-status.md#asset-b6072cd65321065ad3a1)

Set **Pwsh.exe** as the program to run

**Program:**

pwsh.exe

**Add arguments**\*\*:\*\*

-WindowsStyle Hidden -command "Get-CompanyDevicesBySchoolBestEffort"

**Click Next**

[Screenshot retained for review](../../review/Review-status.md#asset-e194e6bd176a7a3a3aee)

**Tick** the box next to "Open the Properties dialog box for this task when I click Finish"

[Screenshot retained for review](../../review/Review-status.md#asset-4fb451d6a53a210bcdcf)

Click **Finish**

**OPTINAL PROPERTIES** **- Run When Not Logged In**

    - Select the Radio button as circled below. "Run whether user is logged on or not"

- **Don't store the password Unless**
- You are trying to access a remote device during the script.
- Avoid this.
- Your internet connection requires you to be signed into to be able to access the Internet. You could use a non admin/IT account to get your internet access. If a script is run from an on-prem server then it's IP is typically allowed on to the Internet without user auth so you shouldn't need to store the password.
- **Optional but not ideal.**
- If the script authenticates to M365 through an enterprise App using a certificate, you don't need to store a password.
- **Ideally**
- Once you have a script that can run through an M365 Enterprise App you should run it in a Runbook or similar and have the script use creds that are stored in Azure Key Vault.
- The source records incomplete adoption as at 13 March 2026; current adoption has not been checked.

[Screenshot retained for review](../../review/Review-status.md#asset-eb35c682d35918f3e96c)

## Related guidance

- [Topic overview](Introduction.md)
- [Source review status](../../review/Review-status.md)
