You can override these settings if you want. For example, you can allow execution
of non-signed scripts by changing the current execution policy. To view your current
execution policy, run this command:
Get-ExecutionPolicy
Four execution policies are available:
?–? Restricted (Default) No scripts are allowed.
?– AllSigned Only signed scripts are allowed.
?– RemoteSigned Locally executed scripts are allowed. Anything else must be
signed.
?–? Unrestricted All scripts are allowed.
443 Chapter 13: Windows PowerShell
To change the execution to RemoteSigned (minimally recommended if you must
run unsigned scripts locally), you can change it by running the following command:
Set-ExecutionPolicy RemoteSigned
You can also change the execution policy using Group Policy if you want to make this
change across your organization from a central location.
Hands-On Exercise: Your First PowerShell Script
Before we go on to the details of the various components used in creating scripts, let??™s
take a moment to put together a short script to help show how you can create a script
and run it within PowerShell??”assuming you have changed your execution policy to at
least RemoteSigned so that local scripts are allowed to be executed without having to
sign them.
1. Open Notepad and enter the following code:
$s = "Hello World!"
write-host $s
2. Save the file as C:\helloworld.ps1.
Pages:
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470