How To Run PowerShell Scripts

Powershell is a powerful scripting language that can automate tasks and manage systems. You can write your own scripts or use existing ones to perform various functions.

Enable Script Execution

By default, Windows does not allow you to run Powershell scripts for security reasons. You need to change the execution policy to enable script execution. To do this, you need to open a Powershell window as an administrator. You can do this by pressing the Windows key, typing PowerShell, right-clicking on the result, and selecting Run as administrator.

In the PowerShell window, type the following command and press Enter:

Set-ExecutionPolicy -Scope Process Unrestricted

This command will allow you to run scripts that are not signed by a trusted publisher or downloaded from the internet. This execution policy is only applicable to the current PowerShell session you are running. You can learn more about the execution policies here: ExecutionPolicy

Validate Script ExecutionPolicy

To validate your current ExecutionPolicy enter the command below:

Get-ExecutionPolicy

Your PowerShell Terminal should display the following:

Locate the Script File

Next, you need to find the path of the script file that you want to run. You can use the File Explorer to navigate to the folder where the script is stored. You can also use the PowerShell commands to change directories and list files. For example, you can use the following commands to go to the Desktop folder and display the files there:

cd C:\Users\YourUserName\Desktop
dir

You can also use the tab key to autocomplete the file or folder names. You can also drag and drop the script file from the File Explorer to the Powershell window to get the full path.

Run PowerShell Script

Finally, you can run the script by typing the following command and pressing Enter:

.\ScriptName.ps1

The dot and backslash indicate that the script is in the current directory. You can also use the full path of the script if it is in a different location. For example, you can use the following command to run a script that is on the Desktop:

C:\Users\YourUserName\Desktop\ScriptName.ps1

You may see a warning message that the script is from an untrusted source. This is because the script is not signed by a trusted publisher. You can choose to run the script by typing R and pressing Enter. You can also type N to cancel or A to run all scripts from untrusted sources.

The script will execute and display the output or results in the Powershell window. 

Need Help?

Sendmarc does not provide any support for PowerShell scripts and are run at your own risk.