How to Run PowerShell Scripts From the Command Line
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
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."
Type "Set-ExecutionPolicy Unrestricted" and press "Enter." Type "Y" at the command prompt "Execution Policy Change" and press "Enter" to confirm the configuration change.
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.
Type "& C:\getdate.ps1" at the PowerShell command prompt and press "Enter."
If the script executes correctly, it will return the current day, date and time in the PowerShell window.