How to Run PowerShell Scripts From the Command Line

By Keith Perry

PowerShell scripting language provides two methods to execute commands. The interactive mode requires each command line to be typed every time it is executed. Execution of a text file containing the commands allows complex or lengthy scripts to be constructed once and executed many times. This method is useful for scheduling execution of scripts on many different machines. Batch file execution makes administration of multiple machines possible for one administrator.

Things You'll Need

  • PowerShell version 2.0 or later

Step 1

Click on the programs icon located on the Windows task bar. Select "Programs," "Accessories," 'Windows PowerShell," right-click on "Windows PowerShell" and Select "Run as Administrator."

Step 2

Type "Set-ExecutionPolicy Unrestricted" and press "Enter." Type "Y" at the command prompt "Execution Policy Change" and press "Enter" to confirm the configuration change.

Step 3

Open a text editing program on your computer. Enter the text "Get-Date" in the text file and press "Enter." Save the file as "C:\getdate.ps1" on your computer.

Step 4

Type "& C:\getdate.ps1" at the PowerShell command prompt and press "Enter."

Step 5

If the script executes correctly, it will return the current day, date and time in the PowerShell window.