Skip to content

Unable to run scripts

A first thing to test is if you can run the script directly from a PowerShell console. Open pwsh.exe and just try to run the script to see what happens, in many cases this tells you what the problem is and then you can take action on that problem.

Some common issues for not being able to run a script can be found below.

Restricted by Execution policies

PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. This feature helps prevent the execution of malicious scripts.

Read more here: about_Execution_Policies

File is blocked

Files downloaded from "the internet" can be blocked by Windows. The Unblock-File cmdlet lets you open files that were downloaded from the internet. It unblocks PowerShell script files that were downloaded from the internet so you can run them, even when the PowerShell execution policy is RemoteSigned. By default, these files are blocked to protect the computer from untrusted files.

Read more here: Unblock-File

Misspelled Cmdlet or function

We are all humans and misspell things from time to time.

1
2
3
4
5
6
7
8
PS C:\Users\Administrator> C:\Easit\EPR-Test\scripts\testService.ps1
Get-Dates: C:\Easit\EPR-Test\scripts\testService.ps1:6
Line |
   6 |  $date = Get-Dates
     |          ~~~~~~~~~
     | The term 'Get-Dates' is not recognized as a name of a cmdlet, function, script file, or executable program.
     | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\Users\Administrator>

Removing the s in Get-Dates to Get-Date gives us a more correct result when running the script.

1
2
3
PS C:\Users\Administrator> C:\Easit\EPR-Test\scripts\testService.ps1
Todays date is: 03/25/2023 17:18:52
PS C:\Users\Administrator>