Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Windows Server 2012 R2 Administrator Cookbook
Windows Server 2012 R2 Administrator Cookbook

Windows Server 2012 R2 Administrator Cookbook: Over 80 hands-on recipes to effectively administer and manage your Windows Server 2012 R2 infrastructure in enterprise environments

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Windows Server 2012 R2 Administrator Cookbook

Chapter 1. Learning the Interface

In an effort to become familiar with the look and feel of Windows Server 2012 R2, you will learn how to navigate through some daily tasks using the graphical interface. On our agenda in this chapter are the following recipes:

  • Shutting down or restarting the server
  • Launching Administrative Tools
  • Using WinKey + X for quick admin tasks
  • Using the Search function to launch applications quickly
  • Managing remote servers from a single pane with Server Manager
  • Using PowerShell to accomplish any function in Windows Server
  • Installing a role or feature
  • Administering Server 2012 R2 from a Windows 8.x machine
  • Identifying useful keyboard shortcuts in Server 2012 R2
  • Setting your PowerShell Execution Policy
  • Building and executing your first PowerShell script
  • Searching for PowerShell cmdlets with Get-Help

Introduction

I meet new server administrators almost daily, from all types of businesses and walks of life. Often during our projects, we introduce the very first Windows Server 2012 R2 server into an environment. This gives me the unique opportunity to observe first interactions with the updated interface, and most of the time first impressions are pretty terrible. Now don't get me wrong, after using Windows Server 2012 R2 for only a little while, I think you'll all agree that it has some of the best functionality and stability we have ever seen out of a server operating system. What I see people struggle with all the time when starting to use 2012 R2 is the user interface. This is the same challenge that has plagued Windows 8 since its release. Everything seems to look and feel different than the Windows we have always known, trying to find applications can be futile, and what in the world is that "tablet-touch-screen-wannabe-thing" that consumes my entire screen all the time? And the charms bars that pop out? Don't get me started.

These big changes in the way that we interact with the operating system can be a nuisance on a client Desktop machine, but can be downright dangerous on a server until you have a good handle on managing the interface. When you are working within three levels of Remote Desktop Protocol (RDP), bouncing from one server to another, all of these little differences are compounded. It suddenly becomes difficult to know which server it is that you are changing. Let's have a show of hands, how many of you have mistakenly rebooted the wrong server? Or even more likely, how many of you have rebooted your own computer while you were trying to reboot a remote server? I know I have! And not just once.

Hope is not lost! I promise you that once you learn to manage the interface, rather than letting it manage you, some of these changes may start to seem like good ideas. They can increase productivity and the ease of accomplishing tasks—we just need some pointers on making the best use of the new interface.

The recipes in this chapter are dedicated to doing just that. Let's work together to gain a better understanding of why the interface was built the way it is, and learn to take advantage of these new screens and settings.

Shutting down or restarting the server

I just couldn't resist starting with this one. Yes, this seems trivial. Silly even. However, the amount of times that I have watched a simple server restart consume more mouse clicks than creating a Domain Controller has convinced me that this needed to be in the book. Perhaps the shutdown and restart options were hidden away purposefully, because once your system is up and running, there is not often a need to accomplish either of these tasks. When first configuring the box though, it is very common to have to reboot a couple of times, or to shut down a machine to move it to another location.

Getting ready

To step through this recipe, you will need a Windows Server 2012 R2 system online. There are no other prerequisites.

How to do it...

Let's take a look at three different ways to shut down or restart your system. The first two are the most commonly employed. The third is less commonly known, but is by far my preference when tasked with restarting a remote server.

The first option would be to use the power button on the Start screen. So far, I don't think that many administrators have stumbled into this one, because it didn't exist in Server 2012.

  1. Click on your "Start Button", or rather your button in the Taskbar that opens your Start screen. You will see a power icon in the top-right corner of that Start screen.
  2. Click on this for Shut down and Restart options.
    How to do it...

The second method to accomplish shutting down or restarting is by using the charms bar. The charms bar is the little menu that presents itself when you have your mouse sitting near the upper-right corner of your screen. On a touchscreen computer, you swipe your finger from the right side of the screen toward the middle to make it appear. Go ahead and hover the mouse in the upper-right corner of your screen until the charms bar appears. Then click on Settings, and then on Power. Unfortunately, this is the most common way to attempt to restart a Server 2012 R2 machine. I say unfortunately because it is so easy to hover in the corner and display the wrong charms bar, the one for your own Desktop for example.

Many mistaken reboots are caused by this.

How to do it...

The most definitive, and dare I say most fun way of restarting your server is to utilize Command Prompt. Doing this gives you the opportunity to double check that you are manipulating the correct machine. Open up Command Prompt and run a quick hostname check to make sure you are restarting the one you really intend to. Then utilize the shutdown command to take care of the rest. This process can be especially helpful when logged into remote servers using RDP. Use the following commands to perform the explained operations:

hostname
shutdown /r /t 0

If you were to simply type shutdown, the server would shut itself down in 60 seconds. Using /r indicates a restart rather than a shut down, and /t 0 is a timing flag that indicates the number of seconds the server should wait before restarting. Specifying slash zero here tells it to wait for zero seconds before initiating the restart.

How to do it...

How it works...

Shutting down or restarting a server doesn't require a lot of explanation, but I hope that this small recipe gets some thought going about creative ways to do regular tasks. As you will see throughout this book, you can accomplish anything in Windows Server 2012 R2 through the use of commands or scripts. You could easily turn the shutdown command, the last example that we tested in this recipe, into a batch file, and place it on the Desktop of each of your servers as a quick double-click option for accomplishing this task.

However, I work with RDP windows inside RDP windows very often. When you're bouncing around between a dozen servers that all have the same background, I have decided that the only sure-fire way to make sure you are restarting the correct device is to do a quick hostname check before you initiate the restart. If you are interested in discovering all of the available flags that are available to use with the shutdown command, make sure to type in shutdown /? some time to take a look at all of the available options.

Tip

Using the command prompt is also an easy way to log off a server. Let's say you are layers deep in RDP and want to log off from a single server (not all of them). Are you sure you clicked on the Start button of the right server? Instead, open up a prompt and simply type Logoff.

Launching Administrative Tools

Earlier versions of Windows Server placed all of the Administrative Tools in a self-named folder right inside the Start menu. Server 2012 R2 no longer has a Start menu, but rather a full Start screen. It is my experience that administrators prefer to stay on the Desktop as much as possible, and do not like switching back and forth between the two. In other words, they want to accomplish everything without having to use the Start screen. Let's take a look at some ways to launch Administrative Tools right from your server's familiar Desktop interface.

Getting ready

All you really need is a Windows Server 2012 R2 machine online. The more roles and services that you have running on it, the more options that you will see on your screen as we navigate these menus.

How to do it...

To launch Administrative Tools from your Desktop, perform the following steps:

  1. Open up Server Manager. In fact, if you just logged into the server, it's probably already open for you.
  2. Click on Tools in the upper-right corner.

There you go. A full list of all the admin tools installed onto that server. Heading into this list is also a quick way of taking a look into what a particular server is doing, which you can take an educated guess at based on what roles and services are installed. By looking at the screenshot below, we can see that this is a pretty standard server instance that is not yet running any big roles. Once added, the management tools for the Windows roles will present themselves in this list.

How to do it...

How it works...

Since Server Manager likes to open automatically when logging in, let's make quick use of it for opening the tools that we need to do our jobs. Another way to have easy access to your tools from the Desktop is to create shortcuts, or to pin each of them to your Taskbar. Sometimes this isn't as easy as it sounds. In the past, these tools were all grouped together in the Administrative Tools folder, so you didn't have any reason to memorize the exact names of the tools. If you were to head into the Start screen and try to recall the name of the service you are looking for to type into the Search field, it may not immediately come to you. If you're a consultant working on someone else's server, you may not want to pin anything to their Desktop anyway, and you certainly don't want to resort to using Bing in front of them to look up the name of the service. So I like to stick with launching Administrative Tools from Server Manager.

Using WinKey + X for quick admin tasks

There are some functions in Windows that a server administrator needs to use all the time. Instead of making shortcuts or pinning them all to the Taskbar, let's get to know this hidden menu that is extremely useful for launching these commonly used admin tools.

Getting ready

A running Windows Server 2012 R2 machine is all we need to highlight this one. In fact, this menu also exists on any Windows 8.x computer, so make use of it often!

How to do it...

There are two ways to open this little menu. While you are in the Server 2012 R2 Desktop, you can perform either of these steps:

  • Hold down your Windows key on the keyboard and press X
  • Hover your mouse over the Windows flag in the lower-left corner of the Desktop. You know the button that opens the Start screen if you left click on it. Now go ahead and right-click on that button and you will see a menu as shown in the following screenshot:
    How to do it...

How it works...

This little "quick-tasks admin menu" is very easy to open, and is very convenient for launching programs and settings that are accessed often. I won't talk too much about what particulars are in the menu as it's pretty self-explanatory, but I use this menu multiple times per day to open up the System properties and the command prompt. Particularly the command prompt, as it has an option to open an administrative command prompt right from the menu.

Tip

Look at that, you can also shut down the server from here!

Using the Search function to launch applications quickly

We are finally going to make some use of that Start screen. While many server administrators prefer to work outside of this screen 100 percent of the time, the powerful Search functions of the Start screen are definitely something that you should be aware of.

Getting ready

For this recipe, you will need a Windows Server 2012 R2 system online.

How to do it...

To search in Windows Server 2012 R2, we have to make our way to the Start screen. Fortunately, this is extremely easy to do. No matter where you are or what application you are in, if you press the Windows key or click on the Start button, you will be taken to the Start screen.

How to do it...

Now you simply start typing. Search results for anything found on the system that relates to the word you are inputting are automatically displayed. Once you see the item you are looking for, you can press Enter or click on it. Additionally, if you right-click on the item or hold down the Ctrl key while clicking it, you will receive additional options that you can perform with this application. For example, right-click or Ctrl click in order to launch command prompt as an administrator.

How to do it...

By default, your search will encompass the entire operating system. If you would rather narrow the scope of your search down to only Settings or Files, you can use the Everywhere dropdown and choose accordingly.

How to do it...

You can see it is very easy not only to open applications, but also its specific settings.

How to do it...

How it works...

From the Start screen, we can search for anything on the server. This gives us the ability to quickly find and launch any program or application that we have installed. This includes Administrative Tools. Rather than moving into Server Manager in order to launch your administrative consoles from the Tools menu, you can also search for them on the Search screen, and launch from there. It also gives us the ability to find files or documents by name. Another powerful way to use the Search function in Windows Server 2012 R2 is to open any kind of setting that you might want to change. In previous versions of Windows, you had to either memorize the way to get into the settings that you wanted to change or you had to open up Control Panel where you had to poke and prod your way around until you stumbled upon the one that you were looking for. Now it is a very simple matter of pressing the Windows key, typing the first few characters of the setting or program you want to launch, and pressing Enter.

Another common task to perform from the Search screen is to right-click on the application that you are trying to launch and pin it somewhere. When you right-click on a program from the Search screen, you see options to pin the program to either your Start screen or to the Taskbar. This will create a quick-launch shortcut on either the main Start screen or on the Taskbar of the Desktop mode, giving you easier and faster access to launch those applications in the future.

Managing remote servers from a single pane with Server Manager

As you have already noticed, Server Manager has changed significantly as of Server 2012, and has been made even better in Server 2012 R2. Part of these changes are a shift in mindset where emphasis is now placed on remote management of servers. Server Manager in Windows Server 2012 R2 can be used to manage and administer multiple systems at the same time, all from your single pane of glass, the monitor where you are sitting. In this recipe, you are going to learn how to manage both the local server we are logged into, as well as a remote server, from the same Server Manager window.

Getting ready

For this recipe, we need two servers. One is the machine we are physically logged into. Another is a server on the same network that we can contact from our primary server, so that we can manage it from our local Server Manager.

How to do it...

To manage a local as well as a remote server from the same Server Manager window, perform the following instructions:

  1. Log in to your primary server and launch Server Manager. You will see in the upper-left corner that the only server you have listed is the Local Server that we are logged into.
    How to do it...
  2. Now head over toward the top-right of Server Manager and click on the Manage button. In this menu, click on Add Servers.
    How to do it...
  3. If your servers are part of a domain, finding remote machines to manage is very easy by simply selecting them from the default Active Directory tab. Since mine are not yet part of a domain, I need to head over to the DNS tab and specify the name or IP address of the server that I want to connect to.
    How to do it...
  4. Now if you go ahead and click on All Servers in the left window pane, you will see the additional servers listed that you have selected. If you double-click or right-click on those remote server names, you have many options available to you to remotely manage those machines without having to log into them.
    How to do it...

How it works...

Server Manager makes use of the Windows Remote Management (WinRM) tools to remotely manipulate servers. Historically, most of us who are administering Windows Servers make extensive use of RDP, often having many windows and connections open simultaneously. This can cause confusion and can lead to tasks being accomplished on servers for which they are not intended. By using Server Manager from a single machine to manage multiple servers in your network, you will increase your administrative efficiency as well as minimize human error by having all management happen from a single pane of glass.

This recipe is written with the most common network scenario in mind, which is a domain environment where both servers have been joined to the domain. If you are working with standalone servers that are part of a workgroup, rather than being joined to a domain, you will have some additional considerations. In the workgroup scenario, WinRM will need to be enabled specifically, and the Windows Firewall will have to be adjusted in order to allow the right ports and protocols for that WinRM traffic flow to happen successfully. In general though, most of you will be working within a Microsoft domain network, in which case these items are not necessary.

See also

  • The Administering Server 2012 R2 from a Windows 8.x machine recipe

Using PowerShell to accomplish any function in Windows Server

An incredibly powerful tool in Windows Server 2012 R2 is PowerShell. Think of PowerShell like a command prompt on steroids. It is a command-line interface from which you can manipulate almost anything inside Windows that you may care to. Better yet, any task that you may wish to accomplish can be scripted out in PowerShell and saved off as a .ps1 script file, so that you can automate large tasks and schedule them for later, or at regular intervals. In this recipe, let's open up PowerShell and run some sample commands and tasks just to get a quick feel for the interface. In a later chapter of the 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 2012 R2 installed. PowerShell is installed and enabled by default.

How to do it...

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

  1. Right-click on your blue PowerShell icon and make sure to open PowerShell as administrator by clicking on Run as administrator. PowerShell is very powerful, but only if you have admin rights in the session.
    How to do it...
  2. Test out some commands that you are familiar with from using the command prompt, such as dir and cls. Since you are able to make use of these familiar commands, PowerShell can really be your one and only command-line interface if you choose.
  3. Now let's try some of the PowerShell secret sauce, 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 manipulation of server components. Let's start by pulling some data. Maybe take a look at what IP addresses are on the system with Get-NetIPAddress.
    How to do it...
  4. The previous command probably gave you a lot more information than you needed, since most companies don't make use of IPv6 inside their network yet. Let's whittle this information down to the IPv4 specific info that you are most likely interested in. Enter Get-NetIPAddress –AddressFamily IPv4 to attain it.
    How to do it...

How it works...

PowerShell has so many commands and cmdlets, we just wanted to get a feel for launching the program and pulling some data with this particular recipe. There are countless Get commands 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, there are not only Get cmdlets, but also 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. We will dive further into PowerShell in a later chapter.

Installing a role or feature

You've installed the Windows Server 2012 R2 operating system onto a piece of hardware. Great! Now what? Without adding roles and features to your server, it makes a great paper weight. We're going to take the next steps here together. Let's install a role and a feature into Windows so that we can start making this server work for us.

Getting ready

As long as you have a Windows Server 2012 R2 installed and running, you are ready to install roles and features onto that machine.

How to do it...

To install a role and a feature into Windows, perform the following steps:

  1. Open Server Manager. In the middle of the screen, you'll see a link that says Add roles and features. Click on that link.
  2. Click Next on the first summary screen and you will come to a choice on the second page. For most roles and features, we want to leave it set at the top bullet, which is Role-based or feature-based installation. If we were configuring Remote Desktop Services, which we will discuss in another chapter, then we would choose the second option.

    Now we choose where we want to install a new role or feature. This is a neat page, as we can choose from any server that we have added into our Server Manager, or we can even choose to install a role or feature into a virtual hard disk. I am running the Add Roles Wizard from DC-01, but I want to install the IIS role onto WEB-01. Rather than having to log into WEB-01 to accomplish this task, I will do it right from here. In the screenshot below, you can see WEB-01 listed as a server that I can install a role onto, even though I am opening this console on the DC-01 server.

    How to do it...
  3. Scroll down and choose the role that you want to install. For DC-01, I am choosing the Web Server (IIS) role. Then click Next.

    Tip

    You can install more than one role or feature at a time.

    Note

    Some roles require additional components to be installed for them to work properly. For example, when I chose to install the IIS role and clicked Next, I was prompted about needing to install some management tools. Simply click on the Add Features button to automatically add the items that it needs to perform correctly.

  4. Now choose any features that you would like to install. For example, in order to do some network connectivity testing later, go ahead and select Telnet Client from the list.
  5. Read and click Next through the informational messages that are displayed. These messages will vary depending on which roles and features you have installed.
  6. The final screen is your installation summary. If everything looks correct, go ahead and click on Install.

After your roles and features have finished installing, the server may or may not have to reboot. This depends on whether or not the role installation requires it. Following installation, or following the reboot, if your new role needs any additional configuration or setting up to be completed, you will be notified at the top of the Server Manager screen.

How it works...

Adding roles and features to a Windows Server is something that every administrator will have to do sooner or later. These items are necessary to turn on the functions in the server that will perform tasks that need to be performed in your environment. Adding roles is quite straightforward. However, it is interesting to see the options that are available to add more than one role or feature at a time. Moreover, the ability to remotely install these items for servers in your network that you are not logged into is intriguing.

Administering Server 2012 R2 from a Windows 8.x machine

In the Managing remote servers from a single pane with Server Manager recipe, we already discussed remotely administering another server by using Server Manager. Did you know we can accomplish the same remote management by using our day-to-day Windows 8.x computer? We will install and use the Remote Server Administration Tools (RSAT) to take even more advantage of Server 2012 R2's remote management ideology.

Getting ready

To test out the RSAT tools, we will need a Windows 8.x client machine. We will then also need a Windows Server 2012 R2 system online, and on the same network, which we can remotely control and manage.

How to do it...

To remotely manage a server using RSAT, perform the following instructions:

  1. First we need to download the RSAT tools. You can use Bing to search for "Remote Server Administration Tools for Windows", or use this link to download RSAT for Windows 8.1: http://www.microsoft.com/en-us/download/details.aspx?id=39296. Here is also the link for the same RSAT tools in Windows 8.0 flavor: http://www.microsoft.com/en-au/download/details.aspx?id=28972.

    After you install these tools onto your Windows 8.x computer, you should now have a copy of Server Manager installed onto your computer. Go ahead and launch that from the Start screen. You can pin it to your Taskbar for quicker launching in the future, of course. In the same fashion, as with Server 2012 R2, you can use the Manage menu to add servers to Server Manager.

    How to do it...

    For this recipe, I do have the machines we are working with joined to a domain, so we will take a look at adding servers that are part of the domain.

  2. Click on the Find Now button and you will see a list of server names that are remotely manageable.
    How to do it...
  3. Click on the server names that you want to administer and click on the arrow to move them over to the right side of the screen. Upon clicking on OK, you will see these new servers listed and ready for management inside your Server Manager console.
    How to do it...

How it works...

Server Manager in Windows Server 2012 R2 is a powerful tool that can be used for the management of not only the local server, but also remote servers that you want to manage. If we take this even a step further and install the RSAT tools on a Windows 8 computer, this gives us the ability to launch and use Server Manager from our everyday Windows 8 computer. In doing so, we enable ourselves the ability to add roles, view events, and restart servers, all from our own desk. Managing servers using these tools will increase productivity and decrease errors, because your entire infrastructure of servers can be available within a single window. This is much more efficient than using the RDP client to connect to many different servers, all in different windows. If you've never tried using RSAT to manage servers, give it a try!

See also

  • The Managing remote servers from a single pane with Server Manager recipe

Identifying useful keyboard shortcuts in Server 2012 R2

I prefer using a keyboard over a mouse any day, for almost any task. There are numerous keyboard shortcuts and tips and tricks that I employ on a daily basis and I want to test them out with you in this recipe. Some of these shortcuts have been around for years and will work with multiple versions of Windows Server; some are new in the Server 2012 R2 operating system. They will all be useful to you as you start working with servers in your network.

Getting ready

We are going to run these commands and keyboard shortcuts while logged into a Windows Server 2012 R2 machine.

How to do it...

  • Windows key: Opens the Start screen where you can start typing to search for programs.
  • Windows key + X: Opens the Quick Links menu, which we discussed in an earlier recipe.
  • Windows key + C: Opens the main charms bar.
  • Windows key + I: Opens the Settings charms bar specifically.
  • Windows key + D: Shows or hides the Desktop. If you are in the Start screen, this is one way to get back over into the Desktop quickly.
  • Windows key + R: Opens the Run box.
  • Windows key + M: Minimizes all windows.
  • Windows key + E: Opens File Explorer.
  • Windows key + L: Locks the computer.
  • Alt + F4: Exits the program you are currently working in. This is especially helpful in full screen apps launched from the Start screen, where it is not always obvious how to exit the program with your mouse.
  • Alt + Tab: Displays a list of open programs so you can hop between them.
  • Shift + Delete: Holding down Shift while pressing Delete deletes files without placing them into the Recycle Bin.
  • Using Tab inside command prompt or PowerShell: I cannot believe that I went years without knowing about this one. When you are working inside command prompt, if you type the first letter of a file or folder that exists in the directory where you are working and then press the Tab key, it will auto-populate the rest of the filename. For example, you may be trying to launch a Microsoft update file with a filename that is 15 characters and comprises a mix of numbers and letters. No need to type out that filename! Let's say the file starts with "KB". Simply navigate to the folder where your installer exists, type "KB", and press Tab. The full filename is populated inside command prompt and you can press the Enter key to launch it.

How it works...

Keyboard shortcuts can greatly increase productivity once you are fluent with them. This is not an extensive list by any means, there are many more key combinations that you can use to launch apps, minimize and maximize windows, and do all sorts of other functions. This is a list to get you started with the most common ones that I employ often. Start using these with your daily tasks and I bet your mouse will start to feel lonely.

If you are interested in exploring more of the Windows Server 2012 R2 key combinations available, this website is a great place to start: http://technet.microsoft.com/en-us/library/hh831491.aspx.

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 2012 R2 box.

How to do it...

Follow these steps to set the PowerShell Execution Policy:

  1. Right-click on the PowerShell icon from the Taskbar 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 2012 R2, 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.

Building and executing your first PowerShell script

Command prompt and PowerShell are both great command-line interfaces that can acquire and configure information about our servers. Most of us are familiar with creating some simple batch files that are driven by command prompt, essentially programming out small tasks within these batch files to automate a series of commands. This saves time later as we do not have to type out the commands line by line, especially for common tasks or for items that we need to run during login.

PowerShell has similar functionality, the ability to write out multiple lines of PowerShell cmdlets inside a script file. We can then launch this script file as we would a batch file, automating tasks while taking advantage of the additional features that PowerShell brings to the table over command prompt. These PowerShell scripts are put together inside .ps1 files; let's build a simple one together to get a feel for running these scripts.

Getting ready

Our work with PowerShell today will be accomplished from a Windows Server 2012 R2 machine. PowerShell is installed by default with Windows, and there is nothing further that we need to install.

How to do it...

Follow these steps to build and execute our first PowerShell script:

  1. Open the Start screen and type Windows PowerShell ISE. Right-click to launch this tool as an administrator. PowerShell ISE is an editor for PowerShell scripts that is much more useful than opening a simple text editor such as Notepad in order to build our script.
    How to do it...
  2. Choose File | New from the menus in order to open a blank .ps1 script file.
  3. In your first line, type the following: Write-Host "Hello! Here is the current date and time:".
  4. From the toolbar menu, click the green arrow that says Run Script. Alternatively, you can simply press the F5 button. When you run the script, the command and output are displayed in the lower portion of the ISE window.

    How to do it...

    Cool! Okay, so far it's actually pretty lame. Just reflecting the text that we told it to echo, but it worked. That is the nice thing about using the ISE editing tool rather than a generic text editor, you have the ability to quickly test run scripts as you make modifications.

  5. Now let's add some additional lines into our script to give us the information we are looking for. You can see a list of available commands on the right side of the screen if you would like to browse through what is available, but for our example simply change your script to include the following:
    Write-Host "Hello! Here is the current date and time:"
    Get-Date
    Write-Host "The name of your computer is:"
    hostname
    
  6. Press the Run Script button again to see the new output.

    How to do it...
  7. Now use File | Save and save your new .ps1 PowerShell script out to the Desktop.
  8. Let's test this script by launching it from within a real PowerShell command window. Right-click on your PowerShell icon in the Taskbar and choose Run as administrator.
  9. Browse to the location of the script file, I placed mine on the Desktop. Then launch the script by inputting .\filename. In my case, it looks like this: .\time.ps1.
    How to do it...

How it works...

In this recipe, we created a very simple PowerShell script and saved it on our server for execution. While in practice getting time and date information from your server may come faster by using the stand-alone Get-Date cmdlet, we use this recipe to give a small taste of the ISE and to get your scripting juices flowing. Expanding upon the ideas presented here will start to save you valuable time and keystrokes as you identify more and more ways to automate the tasks and information gathering that are part of your daily routines. The possibilities behind PowerShell are practically limitless, so make sure that you open it up and start becoming familiar with the interfaces and tools associated with it right away!

Searching for PowerShell cmdlets with Get-Help

With this recipe, let's take a minute to use Get-Help inside PowerShell in order to, well, get some help! I see both new and experienced PowerShell administrators going to the Web a lot in order to find commands and the parameters of those commands. The Internet is great, and there is a ton of data out there about how to use PowerShell, but in many cases the information that you are looking for resides right inside PowerShell itself. By using the Get-Help cmdlet combined with the functions you are running or searching for, you might not have to open that web browser after all.

Getting ready

We will be running some commands from inside PowerShell on a Windows Server 2012 R2 machine.

How to do it...

To use the Get-Help function inside PowerShell, run the following steps:

  1. Launch a PowerShell prompt.
  2. Type Get-Help.
  3. You're finished! No, I'm just kidding. Using Get-Help by itself will present you with some helpful data about the Get-Help command, but that's not really what we are looking for, is it? How about using Get-Help with a search parameter, like this:
    Get-Help Computer
    
    How to do it...

    Cool! That searched the available cmdlets and presented us with a list of the ones that contain the word Computer. Nice.

  4. Now what if we wanted to find out some more particular information about one of these cmdlets? Maybe about Restart-Computer, that sounds like something we might use often. Use the following command:
    Get-Help Restart-Computer
    
    How to do it...

    Now we're really cooking! This is wonderful information. Basically, this is exactly what you would find if you were looking for information about the Restart-Computer cmdlet and went searching on TechNet for it.

How it works...

The Get-Help cmdlet in PowerShell can be used with virtually any command in order to find out more information about that particular function. I often use it when the specific name of a cmdlet that I want to use escapes my memory. By using Get-Help as a search function, it will present a list of available cmdlets that include the keyword you specified. This is a brilliant addition to PowerShell, and makes it so much more powerful than command prompt.

Also included with the Get-Help files are all of the special syntax and parameter options for each cmdlet that you might be working with. This saves you time from having to go to the Web in order to search for these functions, and it is just way more fun doing it at the command line than in a web browser.

Left arrow icon Right arrow icon

Description

This book is intended for system administrators and IT professionals with experience in Windows Server 2008 or Windows Server 2012 environments who are looking to acquire the skills and knowledge necessary to manage and maintain the core infrastructure required for a Windows Server 2012 and Windows Server 2012 R2 environment.

Who is this book for?

This book is intended for system administrators and IT professionals with experience in Windows Server 2008 or Windows Server 2012 environments who are looking to acquire the skills and knowledge necessary to manage and maintain the core infrastructure required for a Windows Server 2012 and Windows Server 2012 R2 environment.
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 28, 2015
Length: 310 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393076
Vendor :
Microsoft

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Estimated delivery fee Deliver to Malta

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

Product Details

Publication date : Jan 28, 2015
Length: 310 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393076
Vendor :
Microsoft

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 124.97
Windows Server 2012 Automation with PowerShell Cookbook
€45.99
Active Directory with PowerShell
€36.99
Windows Server 2012 R2 Administrator Cookbook
€41.99
Total 124.97 Stars icon

Table of Contents

11 Chapters
1. Learning the Interface Chevron down icon Chevron up icon
2. Core Infrastructure Tasks Chevron down icon Chevron up icon
3. Security and Networking Chevron down icon Chevron up icon
4. Working with Certificates Chevron down icon Chevron up icon
5. Internet Information Services Chevron down icon Chevron up icon
6. Remote Access Chevron down icon Chevron up icon
7. Remote Desktop Services Chevron down icon Chevron up icon
8. Monitoring and Backup Chevron down icon Chevron up icon
9. Group Policy Chevron down icon Chevron up icon
10. File Services and Data Control Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(13 Ratings)
5 star 76.9%
4 star 15.4%
3 star 0%
2 star 7.7%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




abhimanyu singh rathore Apr 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book covers the topic which are the most needed for system admins, i definitely recommend this book
Amazon Verified review Amazon
William R James Jun 28, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Simple, straight forward, meaningful, to the point, not long-winded.
Amazon Verified review Amazon
Charbel Nemnom Mar 05, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I recommend this book for every IT Pro, you will know how to take your Windows Server 2012 R2 - powered server and turn it into any common infrastructure role that might be required in your organization.Get your copy today and enjoy!
Amazon Verified review Amazon
William Payne Mar 29, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book
Amazon Verified review Amazon
Charles W. Hayes Jul 14, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A great book for system admins.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela