Set ExecutionPolicy on the Server PowerShell is secure by default. The first thing keep in mind that PowerShell won't execute scripts until you allowd to execute it means explicitly you have to give it permission to do so. PowerShell has four execution policies that govern how it should execute scripts
Restricted
No scripts allowed
You can set PowerShell's execution policy by using the following cmdlet:
PowerShell won't run any scripts. This is PowerShell's default execution policy
Setting
Unrestricted
No requirements; all scripts allowed
PowerShell ignores digital signatures but will still prompt you before running a script downloaded from the Internet.
RemoteSigned
All local scripts allowed; only signed remote scripts.
PowerShell won't run scripts downloaded from the Internet unless they have a digital signature,
but scripts not downloaded from the Internet will run without prompting. If a script has a digital signature,
PowerShell will prompt you before it runs a script from a publisher it hasn't seen before.
AllSigned
All scripts need to be signed
PowerShell will only run scripts that are signed with a digital signature.
If you run a script signed by a publisher PowerShell hasn't seen before,
PowerShell will ask whether you trust the script's publisher.
To view common and other parameters available to the "Set-ExecutionPolicy" cmdlet, type the following at the command prompt:
Set-ExecutionPolicy -<tab>
You can cycle through available parameters, for a cmdlet, by continually pressing the "tab" key. Make sure you are using the dash "-" before pressing tab. Note: not only will you see common parameters but, other parameters that are available as well.
Use the "Get-Help" cmdlet for information on parameters available to a cmdlet. Continuing to use the "Set-ExectutionPolicy" cmdlet, let's get-help:
Get-Help Set-ExecutionPolicy -Full<enter>
In the "Parameters" section, which provides information on parameters available to the cmdlet, there is a list of the common parameters the cmdlet supports.
Examples:
1. In this example, let's use the -whatif parameter to see "what would happen" if we used the "Set-ExecutionPolicy" cmdlet:
Set-ExecutionPolicy Unrestricted -whatif<enter>
You are presented with the following:
Performing operation "Set-ExecutionPolicy" on Target "Unrestricted".
This is really cool... before you commit any changes you can verify that the
cmdlet is going to do what's expected. Would have been great if "Format C:" had a -whatif parameter.
2. Using the same cmdlet, choose the -confirm parameter to prompt before executing:
Set-ExecutionPolicy Unrestricted -confirm<enter>
Are you sure you want to perform this action?
Note: Suspend? This option is very useful. Let's say you are not sure you want to execute the cmdlet because you are not sure what the "ExecutionPolicy" is set to. You can verify the "ExecutionPolicy" before committing the change:
Set-ExecutionPolicy Unrestricted -confirm<enter>
Are you sure you want...
S<enter> (places the prompt in suspend mode as denoted by ">>").
>>Get-ExecutionPolicy<enter>
Resricted (or whatever the policy is set to).
>>exit<enter> (Typing "exit" leaves suspend mode and returns to the original command)
Are you sure you want...
Y<enter> (Confirms "Yes" and sets the ExecutionPolicy to "Unrestricted").
We've covered a few examples of what you can do with parameters. Since you know how to "Get-Help" for a cmdlet, it's easy to discover which parameters are available to any cmdlet. Do some exploring and experimentation before moving on to the "Objects" section.