16.1. Minimizing the Default Risk

When you install Windows PowerShell, there are several factors that reduce the chances of any malicious script being run. By default, immediately after you install PowerShell you can't run Windows PowerShell scripts at all.

If, with a default installation of Windows PowerShell, you attempt to run a Windows PowerShell script (in any of a number of ways, as described in this section), you run into a brick wall. Double-clicking on a script in Windows Explorer causes the script to open in Notepad

Similarly, if you attempt to run a script by right-clicking on it and choosing the Open option from the context menu, the script is again opened in Notepad.

Right-clicking on a script and selecting the Open With option, then selecting Windows PowerShell from C:\WINDOWS\system32\windowspowershell\v1.0 fails to add Windows PowerShell to the list of programs that can open a .ps1 file. I also tried copying the shortcut to Windows PowerShell to the desktop and then tried to add that shortcut to the list of programs to open the script, but the error message shown in Figure 16-1 was displayed.

Figure 16.1. Figure 16-1

I couldn't find a way to make a PowerShell script execute from Windows Explorer. That is a good thing, since it protects each Windows machine from an innocent user double-clicking on a file and executing a malicious script. This protection is permanent. ...

Get Professional Windows® PowerShell 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.