---
title: "Run PowerShell Script From the Command Line and More"
description: "Learn how to get started with PowerShell and how to run PowerShell script in this handy tutorial covering only what you need to know."
canonical: "https://adamtheautomator.com/run-powershell-script/"
---

# Run PowerShell Script From the Command Line and More

> Learn how to get started with PowerShell and how to run PowerShell script in this handy tutorial covering only what you need to know.

Source: https://adamtheautomator.com/run-powershell-script/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Run a PowerShell Script From the Command Line and More](https://adamtheautomator.com/wp-content/uploads/2020/12/Back-to-Basics_-How-to-Run-a-PowerShell-Script.jpg)

# How to Run a PowerShell Script From the Command Line and More

[![](https://secure.gravatar.com/avatar/99e90b07e3592c07611180aab9394a6120d139bda6738a1ffd2fd531605bacf3?s=192&d=mm&r=g)Parveen Singh](https://adamtheautomator.com/author/parveen/)12 November 20216 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Dealing with the Execution Policy](#h-dealing-with-the-execution-policy)
*   [Restricted](#h-restricted)
*   [Unrestricted](#h-unrestricted)
*   [Remote Signed](#h-remote-signed)
*   [All Signed](#h-all-signed)
*   [Changing the PowerShell Execution Policy](#h-changing-the-powershell-execution-policy)
*   [How to Run PowerShell Script](#h-running-a-powershell-script)
*   [Using the Console](#h-using-the-console)
*   [How to Run a PowerShell Script from the Command Line via the PowerShell Location](#h-running-a-powershell-script-from-the-command-line)
*   [Using the PowerShell ISE](#h-using-the-powershell-ise)
*   [The Sample Script’s Output](#h-the-sample-script-s-output)

If you’re new to the PowerShell scripting language and want to learn how to run PowerShell script, you’ve come to the right blog post. This blog will be a tutorial covering common ways to run scripts and a few issues that may pop up.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

## Prerequisites

This article will be a walkthrough for you about how to run PowerShell on your local computer. If you’d like to follow along, please be sure you have the following prerequisites in place before starting this article.

*   A Windows 10 computer with Administrator privileges.
*   Windows PowerShell v5 or higher ([_PowerShell v7_](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.1)) – This tutorial uses Windows PowerShell v5.

Related:[Check PowerShell Versions: Best Practices](https://adamtheautomator.com/powershell-version/)

## Dealing with the Execution Policy

If this is the first time you’re trying to execute a Windows PowerShell script, you may run into a common problem. PowerShell will probably return an error message stating that a script “cannot be loaded because running scripts is disabled on this system”.

Related:[PowerShell Execution Policies: Understanding and Managing](https://adamtheautomator.com/set-executionpolicy/)

```powershell
PS> .\GetServices.ps1
 File C:\Temp\GetServices.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
 https:/go.microsoft.com/fwlink/?LinkID=135170.
 At line:1 char:1
 .\GetServices.ps1
 ~~~~~ CategoryInfo          : SecurityError: (:) [], PSSecurityException
 FullyQualifiedErrorId : UnauthorizedAccess   
```

PowerShell returns the error message above when you try to run a PowerShell with an execution policy set to **Restricted**, **Remote Signed** or **All Signed**.

### Restricted

Restricted is the default policy set for Windows client computers. If you are using PowerShell for the first time, your default policy would probably be set to restrict all the scripts.

You can still execute individual commands in a terminal, but not a script file. The restriction includes any file ending with `.ps1xml`, `.psm1` or `.ps1`.

### Unrestricted

Unrestricted allows you to run any script however, it warns you before execution if the script is downloaded from the internet. This policy is usually the default for any non-windows devices.

### Remote Signed

Remote Signed policy allows you to run any script that is either (a) digitally signed or (b) any script written on your local computer with or without a signature.

If a script is downloaded from the internet and not signed, you would need to unblock the file. You can do so by right-clicking on the file and choosing **Properties**. Or, you could use the `Unblock-File` PowerShell cmdlet for that particular script file.

Using a Remote signed policy would be an ideal option when running a script downloaded from the internet.

### All Signed

All signed requires all the scripts to be signed digitally by a trusted publisher. This includes the scripts downloaded from the internet and written locally on your computer.

## Changing the PowerShell Execution Policy

With the different execution policies in mind, you now work on adjusting the restrictions that dictate script execution within PowerShell—changing the PowerShell execution policy. Understanding and tweaking the execution policy is pivotal for unlocking the full potential of PowerShell scripting.

To change the execution policy:

1\. Open **Windows PowerShell** with **Run as Administrator** to ensure you have the highest permission to make the policy changes.

Related:[How to Run PowerShell as Administrator](https://adamtheautomator.com/powershell-run-as-administrator/)

![Search PowerShell in Start Menu](https://adamtheautomator.com/wp-content/uploads/2020/12/04-PowerShellAdminMode.png)

Search PowerShell in the Start Menu

2\. When open, run the following PowerShell command to set your computer’s execution policy. The execution policy, as covered above, can be one of three different types. This tutorial is using a useful yet still secure execution policy of **RemoteSigned**.

Since this tutorial assumes you’ve downloaded from the Internet the _GetServices.ps1_ script file, set the execution policy to **RemoteSigned**.

```powershell
PS> Set-ExecutionPolicy RemoteSigned
```

> _The **RemoteSigned** execution policy forces you to [cryptographically sign](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_signing?view=powershell-7.1) every PowerShell script downloaded from the Internet before PowerShell will run it on your system._

3\. You should see an output requesting to confirm the action. Enter **Y** and hit enter to confirm the policy change.

```powershell
Execution Policy Change
 The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the
 security risks described in the about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to
 change the execution policy?
 [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): 
```

At this point, follow the next steps to explore different methods to run the PowerShell script on your computer.

## How to Run PowerShell Script

To demonstrate running a PowerShell script, you actually need a script file to run! If you don’t have one handy, [_download this ZIP_](https://gist.github.com/singhparveen/b265e3ddf2d0a69707b145d480228882/archive/58b58d3628a98b6724cc752f59a5e4cda5364378.zip) file and extract the PS1 file within. You’ll find a simple script file inside called _GetServices.ps1_.

```powershell
Write-Output "Listing Computer Services"
Get-Service
```

> _Every PowerShell script should end with a `.ps1` extension._

### Using the Console

Once you have a script ready, there are a few different ways you can execute a PowerShell script file. One of the most common ways is via the PowerShell console.

1\. Open the PowerShell console as shown above.

2\. Navigate to the file system location where your script is located using the `Set-Location` PowerShell cmdlet or the `cd` alias. This tutorial’s script is found in the _C:\\Temp_ directory.

```powershell
PS> cd C:\Temp\
```

3\. Run the script using a dot (`.`) notation. PowerShell is a shell that also looks for command names. To differentiate between a PowerShell command and a script, you must preface the script with a dot. This dot represents the current directory.

```powershell
PS> .\GetServices.ps1
```

### How to Run a PowerShell Script from the Command Line via the PowerShell Location

If you can’t or would rather not run scripts via the PowerShell console, you can also do so with the good ol’ command line (command prompt).

To run scripts via the command prompt, you must first start up the PowerShell executable (_powershell.exe_), with the PowerShell location of `C:\Program Files\WindowsPowerShell\powershell.exe` and then pass the script path as a parameter to it.

> _You can run scripts with parameters in any context by simply specifying them while running the PowerShell executable like `powershell.exe -Parameter 'Foo' -Parameter2 'Bar'`._

Once you open _cmd.exe_, you can execute a PowerShell script like below. This example is running the engine and passing it the script path of _C:\\Temp\\GetServices.ps1_.

Notice below that the example below is using the PowerShell location path to run the script. You’ll have to do this if the folder isn’t in your PATH somewhere.

```powershell
CMD> C:\Program Files\WindowsPowerShell\powershell.exe "C:\Temp\GetServices.ps1"
```

> The PowerShell location for PowerShell 7 uses a different executable named _pwsh.exe_ typically located in _C:\\Program Files\\PowerShell\\7\\pwsh.exe_.

Below is a handy YouTube video that covers executing a script via a batch file which the cmd.exe executes.

https://www.youtube.com/watch?v=-IKSBNYs5Jo

### Using the PowerShell ISE

If you create your own scripts or edit others’, you’ll probably be using a script editor like the [_PowerShell ISE_](https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/ise/introducing-the-windows-powershell-ise?view=powershell-7.1) or maybe [_Visual Studio (VS) Code_](https://code.visualstudio.com/). Since the ISE comes with Windows, let’s focus on that method for this tutorial.

To invoke a script via the ISE:

1\. Navigate to Start Menu, search for _PowerShell ISE_ and open it.

![Search PowerShell ISE in Start Menu](https://adamtheautomator.com/wp-content/uploads/2020/12/01-PowerShellISE-1.png)

Search PowerShell ISE in Start Menu

2\. Click on **File** → **Open** and find your script.

![Open Script using File Menu](https://adamtheautomator.com/wp-content/uploads/2020/12/02-OpenISE.png)

Open Script using File Menu

3\. With the script open, click on the green run button to execute the script. This button will invoke the script in the built-in PowerShell terminal at the bottom.

![Run Script using PowerShell ISE](https://adamtheautomator.com/wp-content/uploads/2020/12/03-RunISE.png)

Run Script using PowerShell ISE

### The Sample Script’s Output

A PowerShell script can sometimes return output. This happens when the script you’re executing is built to return _objects_ which is a fundamental component of PowerShell.

Related:[Back to Basics: Understanding PowerShell Objects](https://adamtheautomator.com/powershell-objects/)

If you run the sample _GetServices.ps1_ script, you will see the following. This script runs the `Get-Service` cmdlet which returns all of the services installed on your local Windows computer.

```powershell
PS> .\GetScripts.ps1
Listing Computer Services
Status   Name               DisplayName
------   ----               -----------
Running  aakore             Acronis Agent Core Service
Stopped  AarSvc_1b668d      Agent Activation Runtime_1b668d
Running  AcronisActivePr... Acronis Active Protection Service
Running  AcronisCyberPro... Acronis Cyber Protection Service
Running  AcrSch2Svc         Acronis Scheduler2 Service
Running  AdobeARMservice    Adobe Acrobat Update Service
Running  AdobeUpdateService AdobeUpdateService
Running  AGMService         Adobe Genuine Monitor Service
Running  AGSService         Adobe Genuine Software Integrity Se...
----Truncated----
```

Running a PowerShell Script from Within a Script

Let’s say you have two scripts and you’d like one to call the other. Perhaps you have a script called _GetUser.ps1_ and one called _ResetPassword.ps1_. Inside of the _GetUser.ps1_ script, you’d like to execute the _ResetPassword.ps1_ to reset a user password.

Inside of the calling script (_GetUser.ps1)_, you’d add a line to execute the other script just like you would call the script from the command line.

You can see below you have a couple of options. You should typically choose to run the other script within the same session or scope to simplify things unless you have a specific reason to run the script in another PowerShell session.

```powershell
## To run the other script in a new session
powershell.exe .\ResetPassword.ps1
## To run the other script in the same session
.\ResetPassword.ps1
```

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Frun-powershell-script%2F&text=How%20to%20Run%20a%20PowerShell%20Script%20From%20the%20Command%20Line%20and%20More)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Frun-powershell-script%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Frun-powershell-script%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
