If you run particular commands or command sequences repeatedly, or if you develop a series of commands to perform a complex task, you will want to save your commands in a file and execute the command file, instead of typing commands at the prompt. A file of commands is called a script.

In addition to its interactive interface, Windows PowerShell fully supports scripting. In Windows PowerShell, script files have a .ps1 file name extension. To run a script, type the name of the script at the command prompt. The file name extension is optional.

For example:




You must specify the fully qualified path to the script file, even if the script is in the current directory. To indicate the current directory, type the directory name or use a dot (.) to represent the current directory. For example:


Although scripts are extremely useful -- even essential -- in some enterprises, they can be used to spread malicious code. As a result, the security policy in Windows PowerShell, called an execution policy, lets you determine whether scripts can run and whether they must include a digital signature. To eliminate an obvious risk, none of the execution policies in Windows PowerShell allow you to run a script by double-clicking its icon. For more information, type:

get-help about_execution_policies

Windows PowerShell also includes a very rich scripting language that allows you to create scripts from the simplest to the very complex. It supports language constructs for looping, conditions, flow-control, and variable assignment.

See Also