Executing Powershell From Cmd Line

In the last article, we verified that Windows PowerShell was installed on my laptop and determined the version of the scripting engine. This tallk will be center around how to execute scripts from the command line.

For a simple test case, I created a C:\TEMP directory. Inside that directory is a script named “LIST-ROOT.PS1” that will change the directory to the root node on the C drive. After this action, the contents of the root directory is listed for review.

Lets try executing the script from a command line. Use the -F option to specify the location of the file. As we can see below, the command fails since the script is not signed.


For now, we will allow unrestricted access since I am the only person on this laptop. In a later article, we will talk about signing the script.

The enclosed MSDN link goes over the three possible settings.

For now, we will use the Get-ExecutionPolicy applet to find out the current state and change the setting with the Set-ExecutionPolicy applet.


Let’s try running this script again with the new execution policy. Please note that script engine is smart enough to know that the file name is the script to execute.


In summary, if you are having issues running a script from the command line, please check the execution policy.

Related posts

Leave a Comment