Running Windows PowerShell Scripts

You can't simply double-click a Windows PowerShell script and have it run. You cannot type the name in the Start | Run dialog box, either. If you are inside Windows PowerShell, you can run scripts if you have enabled the execution policy, but you need to type the entire path to the script you want to run and make sure to include the .ps1 extension.

If you need to run a script from outside Windows PowerShell, you must type the full path to the script, but you must also feed it as an argument to the PowerShell.exe program. In addition, you probably want to specify the -noexit switch so you can read the output from the script inside the Windows PowerShell console. This syntax is shown in Figure 2-5.

Figure 2-5. To ...

Get Windows PowerShell™ Scripting Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.