SHORT DESCRIPTION Describes how to write and run scripts in Windows PowerShell.
LONG DESCRIPTION A script is a plain text file that contains one or more Windows PowerShell commands. Windows PowerShell scripts have a .ps1 file name extension.
Writing a script saves a command for later use and makes it easy to share with others. Most importantly, it lets you run the commands simply by typing the script path and the file name. Scripts can be as simple as a single command in a file or as extensive as a complex program.
Scripts have additional features, such as the #Requires special comment, the use of parameters, support for data sections, and digital signing for security. You can also write Help topics for scripts and for any functions in the script.
HOW TO WRITE A SCRIPT
A script can contain any valid Windows PowerShell commands, including single commands, commands that use the pipeline, functions, and control structures such as If statements and For loops.
To write a script, start a text editor (such as Notepad) or a script editor (such as the Windows PowerShell Integrated Scripting Environment [ISE]). Type the commands and save them in a file with a valid file name and the .ps1 file name extension.
The following example is a simple script that gets the services that are running on the current system and saves them to a log file. The log file name is created from the current date.
$date = (get-date).dayofyear get-service | out-file "$date.log"
To create this script, open a text editor or a script editor, type these commands, and then save them in a file named ServiceLog.ps1.
HOW TO RUN A SCRIPT
Before you can run a script, you need to change the default Windows PowerShell execution policy. The default execution policy, "Restricted", prevents all scripts