Book Image

Microsoft Exchange Server 2016 PowerShell Cookbook - Fourth Edition

By : Jonas Andersson, Nuno Mota, Mike Pfeiffer
Book Image

Microsoft Exchange Server 2016 PowerShell Cookbook - Fourth Edition

By: Jonas Andersson, Nuno Mota, Mike Pfeiffer

Overview of this book

We start with a set of recipes on core PowerShell concepts. This will provide you with a foundation for the examples in the book. Next, you'll see how to implement some of the common exchange management shell tasks, so you can effectively write scripts with this latest release. You will then learn to manage Exchange recipients, automate recipient-related tasks in your environment, manage mailboxes, and understand distribution group management within the Exchange Management Shell. Moving on, we'll work through several scenarios where PowerShell scripting can be used to increase your efficiency when managing databases, which are the most critical resources in your Exchange environment. Towards the end, you'll discover how to achieve Exchange High Availability and how to secure your environment, monitor the health of Exchange, and integrate Exchange with Office Online Server, Skype for Business Server, and Exchange Online (Office 365). By the end of the book, you will be able to perform administrative tasks efficiently.
Table of Contents (17 chapters)

Using the help system

The Exchange Management Shell includes over 830 cmdlets, each with a set of multiple parameters. For instance, the New-Mailbox cmdlet accepts up to more than 60 parameters, and the Set-Mailbox cmdlet has approximately 200 available parameters. It's safe to say that even the most experienced PowerShell expert would be at a disadvantage without a good help system. In this recipe, we'll take a look at how to get help in the Exchange Management Shell.

How to do it...

To get help information for a cmdlet, type Get-Help, followed by the cmdlet name. For example, to get help information about the Get-Mailbox cmdlet, run the following command:

    Get-Help Get-Mailbox -full  

How it works...

When running Get-Help for a cmdlet, a synopsis and description for the cmdlet will be displayed in the shell. The Get-Help cmdlet is one of the best discovery tools to use in PowerShell. You can use it when you're not quite sure how a cmdlet works or what parameters it provides.

You can use the following switch parameters to get specific information using the Get-Help cmdlet:

  • Detailed: The detailed view provides parameter descriptions and examples and uses the following syntax:
    Get-Help <cmdletname> -Detailed
  • Examples: You can view multiple examples of how to use a cmdlet by running the following syntax:
    Get-Help <cmdletname> -Examples
  • Full: Use the following syntax to view the complete contents of the help file for a cmdlet:
    Get-Help <cmdletname> -Full
  • Online: Use the following syntax to view the online version of the contents for the help file of a cmdlet:
    Get-Help <cmdletname> -Online  

Some parameters accept simple strings as input, while others require an actual object. When creating a mailbox using the New-Mailbox cmdlet, you'll need to provide a secure string object for the -Password parameter. You can determine the data type required for a parameter using Get-Help:

You can see from the command output that we get several pieces of key information about the -Password parameter. In addition to the required data type of <SecureString>, we can see that this is a named parameter. It is required when running the New-Mailbox cmdlet and it does not accept wildcard characters. You can use Get-Help when examining the parameters for any cmdlet to determine whether or not they support these settings.

During the writing of this book there were issues while performing Get-Help New-Mailbox from Exchange Management Shell. I've used an unsupported workaround based on Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 from a regular Windows PowerShell and, from there, performed the Get-Help New-Mailbox cmdlet. This is a known issue and will be solved in the future.

You could run Get-Help New-Mailbox -Examples to determine the syntax required to create a secure string password object and how to use it to create a mailbox. This is also covered in detail in the recipe titled Adding, modifying, and removing mailboxes in Chapter 3, Managing Recipients.

There's more...

There will be times when you'll need to search for a cmdlet without knowing its full name. In this case, there are a couple of commands you can use to find the cmdlets you are looking for.

To find all cmdlets that contain the word "mailbox", you can use a wildcard, as shown in the following command:

    Get-Command *Mailbox*  

You can use the -Verb parameter to find all cmdlets starting with a particular verb:

    Get-Command -Verb Set  

To search for commands that use a particular noun, specify the name with the -Noun parameter:

    Get-Command -Noun Mailbox  

The Get-Command cmdlet is a built-in PowerShell core cmdlet, and it will return commands from both Windows PowerShell as well as the Exchange Management Shell. The Exchange Management Shell also adds a special function called Get-Ex command that will return only Exchange specific commands.

In addition to getting cmdlet help for cmdlets, you can use Get-Help to view supplemental help files that explain general PowerShell concepts that focus primarily on scripting. To display the help file for a particular concept, type Get-Help about_ followed by the concept name. For example, to view the help for the core PowerShell commands type the following:

    Get-Help about_Core_Commands  

You can view the entire list of conceptual help files using the following command:

    Get-Help about_*  

Don't worry about trying to memorize all the Exchange or PowerShell cmdlet names. As long as you can remember Get-Command and Get-Help, you can search for commands and figure out the syntax to do just about anything.

Getting help with cmdlets and functions

One of the things that can be confusing at first is the distinction between cmdlets and functions. When you launch the Exchange Management Shell, a remote PowerShell session is initiated to an Exchange server and specific commands, called proxy functions, are imported into your shell session. These proxy functions are essentially just blocks of code that have a name, such as Get-Mailbox, and that correspond to the compiled cmdlets installed on the server. This is true even if you have a single server and when you are running the shell locally on a server.

When you run the Get-Mailbox function from the shell, data is passed between your machine and the Exchange server through a remote PowerShell session. The Get-Mailbox cmdlet is actually executing on the remote Exchange server, and the results are being passed back to your machine. One of the benefits of this is that it allows you to run the cmdlets remotely regardless of whether your servers are on-premises or in the cloud.

We'll get into the details of all this throughout the remaining chapters in the book. The bottom line is that, for now, you need to understand that, when you are working with the help system, the Exchange 2016 cmdlets will show up as functions and not as cmdlets.

Consider the following command and output:

Here we are running Get-Command against a PowerShell v5 core cmdlet. Notice that the CommandType shows that this is a Cmdlet.

Now try the same thing for the Get-Mailbox cmdlet:

And as you can see, the CommandType for the Get-Mailbox cmdlet shows that it is actually a Function. So, there are a couple of key points to take away from this. First, throughout the course of this book, we will refer to the Exchange 2016 cmdlets as cmdlets, even though they will show up as functions when running Get-Command. Second, keep in mind that you can run Get-Help against any function name, such as Get-Mailbox, and you'll still get the help file for that cmdlet. But if you are unsure of the exact name of a cmdlet, use Get-Command to perform a wildcard search as an aid in the discovery process. Once you've determined the name of the cmdlet you are looking for, you can run Get-Help against that cmdlet for complete details on how to use it.

Try using the help system before going to the internet to find answers. You'll find that the answers to most of your questions are already documented within the built-in cmdlet help.

See also

  • The Understanding command syntax and parameters recipe in this chapter
  • The Manually configuring remote PowerShell connections recipe from Chapter 2, Exchange Management Shell Common Tasks
  • The Working with Role Based Access Control recipe from Chapter 10, Exchange Security