Just type the commands into a Notepad window or
other text editor, and save it to a file with the .ps1 filename extension.
Unfortunately, you can??™t run PowerShell scripts until you jump through a
few hoops to disable some of the security safeguards. The first step is to
check the execution policy by typing:
Get-ExecutionPolicy
If the reply you get is Restricted (the default), then you need to type this
command to allow script execution:
Set-ExecutionPolicy RemoteSigned
To run a script from an open PowerShell window, type the name of the
script file, complete with its path and filename extension, like this:
$home\Desktop\MakeShortcut.ps1
Unlike the Command Prompt, you can??™t leave off the path if the script is in
the same folder as the working folder. For instance, this doesn??™t work:
MakeShortcut.ps1
but this does:
.\MakeShortcut.ps1
The single dot (.) represents the current folder, and is necessary when
launching scripts from the PowerShell command line.
Also, and presumably for security reasons, you can??™t run PowerShell scripts
by double-clicking them until you make a change to your system. To enable
script launching, right-click a .ps1 file, select Open With ??? Choose Default
Program, click Select a program from a list of installed programs, and then
click OK. Click Browse, locate the PowerShell executable (usually C:\Windows\
System32\WindowsPowerShell\v1.0\powershell.exe), and click OK.
By default, the PowerShell window closes when it??™s done
executing a script, but you can change this by modifying the
file type (see Chapter 3) and adding the -NoExit option to
the powershell.
Pages:
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794