Book Image

Windows Server 2019 Cookbook - Second Edition

By : Mark Henderson, Jordan Krause
Book Image

Windows Server 2019 Cookbook - Second Edition

By: Mark Henderson, Jordan Krause

Overview of this book

Do you want to get up and running with essential administrative tasks in Windows Server 2019? This second edition of the Windows Server 2019 Cookbook is packed with practical recipes that will help you do just that. The book starts by taking you through the basics that you need to know to get a Windows Server operating system working, before teaching you how to navigate through daily tasks using the upgraded graphical user interface (GUI). You'll then learn how to compose an optimal Group Policy and perform task automation with PowerShell scripting. As you advance, you’ll get to grips with faster app innovation, improved Windows security measures, and hybrid cloud environments. After you’ve explored the functions available to provide remote network access to your users, you’ll cover the new Hyper-V enhancements. Finally, this Windows Server book will guide you through practical recipes relating to Azure integration and important tips for how to manage a Windows Server environment seamlessly. By the end of this book, you’ll be well-versed with Windows Server 2019 essentials and have the skills you need to configure Windows services and implement best practices for securing a Windows Server environment.
Table of Contents (18 chapters)

Using PowerShell to accomplish any function in Windows Server

As you may have seen earlier in this chapter, an incredibly powerful tool in Windows Server 2019 is PowerShell. Think of PowerShell as a Command Prompt on steroids. It is a command-line interface from which you can manipulate almost anything inside Windows. Better yet, any task that you may wish to accomplish can be scripted out in PowerShell and saved as a .ps1 script file so that you can automate large tasks and schedule them for later or at regular intervals. In this recipe, we'll open up PowerShell and run some sample commands and tasks just to get a quick feel for the interface. In most subsequent chapters of this book, we will do some more specific tasks with PowerShell to go even deeper into the technology.

Getting ready

To start using PowerShell, all you need is a server with Windows Server 2019 installed. PowerShell is installed and enabled by default.

How to do it…

To get a feel for using PowerShell, perform the following steps:

  1. Our first step to working in PowerShell is finding it. Thankfully, Microsoft has begun the process of phasing out the Command Prompt and PowerShell is now accessible in more places than ever before. The most common methods are pressing WinKey + X and choosing Windows PowerShell (Admin), or typing PowerShell into the Start menu, right-clicking it, and choosing Run as administrator:
    Figure 1.13 – Searching in the Start menu for PowerShell

    Figure 1.13 – Searching in the Start menu for PowerShell

  2. Test out some commands that you are familiar with from using the Command Prompt, such as dir and cls. These still work! Since you are able to make use of these familiar commands, PowerShell can really be your one and only command-line interface.
  3. Now, let's try some of PowerShell's secret sauce; that is, one of its cmdlets. These are special commands that are built into Windows and allow us to do all kinds of information gathering, as well as manipulate server components. We will be using many of these commands later on. Let's start by pulling some data. Maybe take a look at what IP addresses are on the system with Get-NetIPAddress:
    Figure 1.14 – Using Get-NetIPAddress to look at IP addresses on a system

    Figure 1.14 – Using Get-NetIPAddress to look at IP addresses on a system

  4. The previous command probably gave you a lot more information than you needed, since a lot of companies don't make use of IPv6 inside their network yet. Let's whittle this information down to the IPv4-specific information that you are most likely interested in. Enter Get-NetIPAddress -AddressFamily IPv4 to attain it:
    Figure 1.15 – Refining your IP address search using –AddressFamily IPv4

    Figure 1.15 – Refining your IP address search using –AddressFamily IPv4

  5. That's more useful! But if you have a lot of data, this would be very difficult to read. PowerShell supports what's called "pipelining" of requests. This means that the output of one command can be directly sent into a second command. PowerShell comes with commands for making output more human readable, and we can use them with pipelining. One very useful command that I use every day is Format-Table. Type Get-NetIPAddress | Format-Table into PowerShell:
Figure 1.16 – Using Format-Table to organize an output

Figure 1.16 – Using Format-Table to organize an output

Tip

PowerShell has a lot of shorthand aliases, which makes typing out commands much easier. For example, you can just use ft instead of typing out all of Format-Table. You can get a list of aliases by running Get-Alias.

How it works…

We just got a feel for some of the many PowerShell commands and cmdlets by launching the program and pulling some data with this particular recipe. There are thousands of Get commands that can be used to query information from the server and, as you have seen, those cmdlets have various parameters that can be appended to the cmdlets to pull more specific data to meet your needs. To make things even better, it also gives us Set cmdlets, which will allow us to make use of the PowerShell prompt to configure many aspects of the configuration on our server, as well as remote servers. Almost every recipe in this book from here on will also show you how to do what we'll be covering in PowerShell.