Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Overview of this book

Table of Contents (22 chapters)
Microsoft Exchange 2010 PowerShell Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

The book is full of immediately-usable task-based recipes for managing and maintaining your Microsoft Exchange 2010 environment with Windows PowerShell 2.0 and the Exchange Management Shell. The focus of this book is to show you how to automate routine tasks and solve common problems. While the Exchange Management Shell provides hundreds of cmdlets, we will not cover every single one of them individually. Instead, we'll focus on common, real-world scenarios. You'll be able to use these recipes right away, allowing you to get the job done quickly, and the techniques that you'll learn will allow you to write your own amazing one-liners and scripts with ease.

What this book covers

Chapter 1, PowerShell Key Concepts, introduces several PowerShell core concepts such as command syntax and parameters, working with the pipeline, and flow control with loops and conditional logic. The topics covered in this chapter lay the foundation for the code samples in the following chapters.

Chapter 2, Exchange Management Shell Common Tasks, covers day-to-day tasks and general techniques for managing Exchange from the command line. Topics include configuring manual remote shell connections, exporting reports to external files, sending e-mail messages from scripts, and scheduling scripts to run with the Task Scheduler.

Chapter 3, Managing Recipients, demonstrates some of the most common recipient-related management tasks, such as creating mailboxes, distribution groups, and contacts. You'll also learn how to manage server side inbox rules, Out of Office settings, and import user photos into Active Directory.

Chapter 4, Managing Mailboxes, shows how to perform various mailbox management tasks that include moving mailboxes, importing and exporting mailbox data, and detecting and repairing corrupt mailboxes. In addition, you'll learn how to delete and restore items from a mailbox and generate some basic reports.

Chapter 5, Distribution Groups and Address Lists, takes you deeper into distribution group management. Topics include distribution group reporting, distribution group naming policies, and allowing end users to manage distribution group membership. You'll also learn how to create Address Lists and Hierarchal Address Books.

Chapter 6, Mailbox and Public Folder Databases, shows how to set database settings and limits and configure Public Folder replication. Report generation for mailbox database size, average mailbox size per database, and backup status are also covered in this chapter.

Chapter 7, Managing Client Access, introduces the concept of Client Access Arrays and covers the creation and configuration of this key component in Exchange 2010. We'll also take a look at controlling connections from various clients, including ActiveSync devices.

Chapter 8, Managing Transport Servers, explains various methods used to control mail flow within your Exchange organization. You'll learn how to create send and receive connectors, allow application servers to relay mail, and manage transport queues.

Chapter 9, High Availability, covers the implementation and management tasks related to Database Availability Groups (DAGs). Topics include creating DAGs, adding mailbox database copies, and performing maintenance on DAG members.

Chapter 10, Exchange Security, introduces the new Role Based Access Control (RBAC) permissions model. You'll learn how to create custom RBAC roles for administrators and end-users, and also how to manage mailbox permissions and implement SSL certificates.

Chapter 11, Compliance and Audit Logging, covers the new compliance and auditing features included in Exchange 2010. Archive mailboxes and Discovery Search are covered here, as well as administrator and mailbox audit logging.

Chapter 12, Server Monitoring and Troubleshooting, shows you how to monitor and report on service availability and resource utilization using PowerShell core cmdlets and WMI. Event log monitoring and Exchange server role troubleshooting tactics are also covered.

Chapter 13, Scripting with the Exchange Web Services Managed API, introduces advanced scripting topics that leverage Exchange Web Services. In this chapter, you'll learn how to write scripts and functions that go beyond the capabilities of the Exchange Management Shell cmdlets.

Appendix A, provides a list of commonly-used automatic shell variables and type accelerators, along with a listing of scripts that are installed with Exchange 2010.

Appendix B, includes additional information about Advanced Query Syntax (AQS), which is used to perform queries when performing discovery searches, item restores, and item removal.

What you need for this book

To complete the recipes in this book, you'll need the following:

  • PowerShell v2, which is already installed by default on Windows 7 and Windows Server 2008 R2.

  • A fully operational lab environment with an Active Directory forest and Exchange organization.

  • Ideally, your Exchange Servers will run Windows Server 2008 R2, but they can run Windows Server 2008 SP2, if needed.

  • You'll need to have at least one Microsoft Exchange 2010 SP1 server.

  • To work with the recipes in this book, you should be logged on with an account that is a member the Organization Management role group. The user account used to install Exchange 2010 SP1 is automatically added to this group.

  • If possible, you'll want to run the commands, scripts, and functions in this book from a client machine. The 64-bit version of Windows 7 with the Exchange 2010 SP1 Management Tools installed is a good choice. You can also run the tools on Windows Vista. Each client will need some additional prerequisites in order to run the tools; see Microsoft's TechNet documentation for full details.

  • If you don't have a client machine, you can run the management shell from an Exchange 2010 SP1 server.

  • Chapter 13 requires the Exchange Web Services Managed API version 1.1, which can be downloaded from the following URL:http://www.microsoft.com/download/en/details.aspx?id=13480

The code samples in this book should be run in a lab environment and should be fully tested before deployed into production. If you don't have a lab environment set up, you can download a pre-configured Hyper-V virtual hard disk (VHD) from Microsoft. It includes a fully-functioning virtual environment with Exchange 2010 SP1 that can be evaluated for 180 days. You can download the files from the following URL:

http://www.microsoft.com/download/en/details.aspx?id=5002

Who this book is for

This book is for messaging professionals who want to learn how to build real-world scripts with Windows PowerShell 2.0 and the Exchange Management Shell. If you are a network or systems administrator responsible for managing and maintaining the on-premise version of Exchange Server 2010, then this book is for you.

The recipes in this cookbook touch on each of the core Exchange 2010 server roles and require a working knowledge of the supporting technologies, such as Windows Server 2008 or 2008 R2, Active Directory, and DNS.

All of the topics in the book are focused on the on-premise version of Exchange 2010 SP1, and we will not cover Microsoft's hosted version of Exchange Online through Office 365. However, the concepts you'll learn in this book will allow you to hit the ground running with that platform since it will give you an understanding of PowerShell's command syntax and object-based nature.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meanings.

Code words in text are shown as follows: "We can read the content of an external file into the shell using the Get-Content cmdlet."

Commands and blocks of code are set as follows:

Get-Mailbox –ResultSize Unlimited | Out-File C:\report.txt

Commands like this can be invoked interactively in the shell, or from within a script or function.

Most of the commands you'll be working with will be very long. In order for them to fit into the pages of this book, we'll need to use line continuation. For example, here is a command that creates a mailbox-enabled Active Directory user account:

New-Mailbox -UserPrincipalName [email protected] `
-FirstName John `
-LastName Smith `
-Alias jsmith `
-Database DB1 `
-Password $password

Notice that the last character on each line is the backtick (`) symbol, also referred to as the grave accent. This is PowerShell's line continuation character. You can run this command as is, but make sure there aren't any trailing spaces at the end of each line. You can also remove the backtick and carriage returns and run the command on one line. Just ensure the spaces between the parameters and arguments are maintained.

You'll also see long pipeline commands formatted like the following example:

Get-Mailbox -ResultSize Unlimited | 
  Select-Object DisplayName,ServerName,Database | 
    Export-Csv c:\mbreport.csv -NoTypeInformation

PowerShell uses the pipe character (|) to send objects output from a command down the pipeline so it can be used as input by another command. The pipe character does not need to be escaped. You can enter the previous command as is, or you can format the command so that everything is on one line.

Any command-line input or output that must be done interactively at the shell console is written as follows:

[PS] C:\>Get-Mailbox administrator | ft ServerName,Database -Auto

ServerName Database
---------- --------
mbx1       DB01

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Open the Exchange Management Shell by clicking on Start | All Programs | Exchange Server 2010."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.