Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Windows Server 2016 Cookbook

You're reading from   Windows Server 2016 Cookbook Sauté your way through more than 100 hands-on recipes designed to prepare any server administrator to work with Windows Server 2016

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher Packt
ISBN-13 9781785883835
Length 494 pages
Edition 1st Edition
Concepts
Arrow right icon
Author (1):
Arrow left icon
Jordan Krause Jordan Krause
Author Profile Icon Jordan Krause
Jordan Krause
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Learning the Interface FREE CHAPTER 2. Core Infrastructure Tasks 3. Security and Networking 4. Working with Certificates 5. Internet Information Services 6. Remote Access 7. Remote Desktop Services 8. Monitoring and Backup 9. Group Policy 10. File Services and Data Control 11. Nano Server and Server Core 12. Working with Hyper-V

Setting your PowerShell Execution Policy

To say that the Windows operating system can be manipulated by PowerShell is a gross understatement. They are fully intertwined, and PowerShell can be useful for so many tasks on your servers. However, the ability to run PowerShell scripts is disabled by default on many machines. The first stumbling block that many new PowerShell administrators bump into is the Execution Policy. It's quite simple: in order to allow PowerShell scripts to run on your server, the Execution Policy must be adjusted to allow that to happen. Let's introduce our first task in PowerShell by using some commands in this recipe that will set this policy for us.

This is also a good introduction to the idea of the verb-noun syntax that PowerShell utilizes. For example, we are going to make use of cmdlets called Get-ExecutionPolicy and Set-ExecutionPolicy. The Get-(parameter name) and Set-(parameter name) cmdlets are very common across all facets of cmdlets available in PowerShell. Wrap your mind around this verb-noun syntax and you will be well on your way to figuring out PowerShell on your machines.

Getting ready

We will be working within a PowerShell prompt on our Windows Server 2016 box.

How to do it…

Follow these steps to set the PowerShell Execution Policy:

  1. Right-click on the PowerShell icon and choose Run as administrator.

    How to do it…

  2. Type Get-ExecutionPolicy and press Enter in order to see the current setting of the PowerShell Execution Policy.

    How to do it…

  3. You can see that the current Execution Policy is set to RemoteSigned. Here is a short description of the different options for the policy:
    • Remote Signed: This is the default setting in Server 2016, which allows PowerShell scripts that are locally created to run. If you try running remote scripts, they must be signed by a trusted publisher in order to execute successfully.
    • All Signed: With this setting, all scripts will only be allowed to run if they are signed by a trusted publisher.
    • Restricted: With this setting, PowerShell is locked down so that scripts will not run.
    • Unrestricted: This setting will allow PowerShell to run scripts, with or without signing.

  4. For the purposes of our recipe and to make sure scripts will run for us as we progress through these recipes, let's set our Execution Policy to unrestricted. Go ahead and use this command:
    Set-ExecutionPolicy Unrestricted
    

    How to do it…

How it works…

The PowerShell Execution Policy is a simple setting and easy to change, but can make a world of difference when it comes to running your first scripts. If configured to be more restrictive than you intend, you will have trouble getting your scripts to run and may think that you have mistyped something, when in fact the issue is only the policy. On the other hand, in an effort to make your servers as secure as possible, on machines where you don't need to execute PowerShell scripts, it makes sense to restrict this access. You may also want to read some additional information on the signing of scripts to see whether creating and executing signed scripts would make more sense in your own environment. There are some in-built server functions that rely on a certain level of security with your Execution Policy. Setting your policy to unrestricted on all of your servers could result in some functions not working properly, and you may have to increase that level of security back to remote signed.

You have been reading a chapter from
Windows Server 2016 Cookbook
Published in: Nov 2016
Publisher: Packt
ISBN-13: 9781785883835
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime