31,19 €
Leverage the power of basic Windows PowerShell scripts to manage your Exchange messaging environment
This book is for administrators with a basic or limited understanding of Windows PowerShell and who want to increase their skill set in managing both the Exchange On Premise and Online environments.
PowerShell has become one of the most important skills in an Exchange administrator's armory. PowerShell has proved its mettle so widely that, if you're not already starting to learn PowerShell, then you're falling behind the industry. It isn't difficult to learn PowerShell at all. In fact, if you've ever run commands from a CMD prompt, then you'll be able to start using PowerShell straightaway.
This book will walk you through the essentials of PowerShell in Microsoft Exchange Server and make sure you understand its nitty gritty effectively.
You will first walk through the core concepts of PowerShell and their applications. This book discusses ways to automate tasks and activities that are performed by Exchange administrators and that otherwise take a lot of manual effort.
Microsoft Exchange PowerShell Essentials will provide all the required details for Active Directory, System, and Exchange administrators to help them understand Windows PowerShell and build the required scripts to manage the Exchange Infrastructure.
This book is written with its target audience in mind; concepts are explained and followed by real-life examples. A comprehensive script is provided in each chapter to give you hands-on practice with all the major commands used in it.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 235
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: February 2016
Production reference: 1190216
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78217-603-9
www.packtpub.com
Author
Biswanath Banerjee
Reviewer
Mark Andrews
Commissioning Editor
Taron Pereira
Acquisition Editor
Manish Nainani
Content Development Editor
Kajal Thapar
Technical Editor
Gebin George
Copy Editor
Yesha Gangani
Project Coordinator
Dinesh Rathe
Proofreader
Safis Editing
Indexer
Rekha Nair
Production Coordinator
Melwyn Dsa
Cover Work
Melwyn Dsa
Biswanath Banerjee has been working with Exchange Servers since 2005 in various roles in support, training, and consulting. Spanning an IT career of over 14 years, he has worked on multiple Active Directory and Exchange migration projects. He specializes in Planning and Deployment of Microsoft Infrastructure Solutions such as Active Directory, Exchange, Lync, Skype for Business, and various Office 365 services.
Mark Andrews career in technology has been a varied one. Over the last 18 years, he has held several different positions ranging from customer service to quality assurance. Throughout all of these positions, the responsibility of configuration management and build management has always fallen either to Mark personally or to one of the groups that he managed; because of his "keeping a hand in" management style, he has been involved closely with the scripting and automation framework for this area. Creating scripted frameworks that intercommunicate across machine/operating system/domain boundaries is a passion for him.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Get notified! Find out when new books are published by following @PacktEnterprise on Twitter or the Packt Enterprise Facebook page.
PowerShell has become one of the most important skills in an Exchange administrator's armory. PowerShell has proved its mettle so widely that, if you're not already starting to learn PowerShell, then you're falling behind the industry. It isn't difficult to learn PowerShell at all. In fact, if you've ever run commands from a CMD prompt, then you'll be able to start using PowerShell straight away.
This book will walk you through the essentials of PowerShell in Microsoft Exchange Server, and make sure you understand its nitty gritty effectively. There are a lot of examples and scripts that will demonstrate how you can use PowerShell to be more effective and save time as an administrator, which otherwise would have been spent performing repetitive tasks.
Microsoft Exchange PowerShell Essentials will provide all the required details for Active Directory, System, and Exchange administrators to help them understand Windows PowerShell and build the required scripts to manage the Exchange Infrastructure.
Chapter 1, Getting Started with PowerShell, provides an introduction to Windows PowerShell, which will build a strong foundation for the latter chapters.
Chapter 2, Learning Recipient Management, teaches you ways to manage recipients in an Exchange organization.
Chapter 3, Handling Distribution Groups, is about managing different distribution groups as it plays a major role in the Exchange Administration.
Chapter 4, Exchange Security, talks about securing Exchange and delegating access to administration tasks using Role-Based Access Control.
Chapter 5, Everything about Microsoft Exchange Policies, covers how to manage address books, email addresses, and Retention Policies in Exchange 2013 and Exchange 2016.
Chapter 6, Handling Exchange Server Roles, talks about configuring Exchange Client Access such as POP, IMAP, Outlook Anywhere, ActiveSync, and different Transport Services.
Chapter 7, Auditing and E-Discovery, reviews auditing and discovery features in Exchange that will help Organizations meet their Compliance and e-discovery requirements.
Chapter 8, Managing High Availability, uses our knowledge of PowerShell to manage high availability for Exchange 2013 and 2016 Organization.
Chapter 9, Exploring EWS Managed API, reviews Exchange Web Services application programming interface (API) and its usage in managing an Exchange On Premise and Online Organization.
Chapter 10, Common Administration Tasks, reviews some of the common administrative tasks in Exchange and uses PowerShell to save time and effort spent in performing repetitive jobs.
The following is a list of softwares and supported operating systems required for this book:
Component
Requirement
Processor
Memory
Varies depending on Exchange roles that are installed:
Paging file size
The minimum of page file size must be set to physical RAM plus 10 MB, to a maximum size of 32778 MB if you're using more than 32GB of RAM.
Disk space
Drive
DVD-ROM drive, local, or network accessible
Screen resolution
1024 x 768 pixels or higher
To view complete system requirements of Exchange Server 2016, you can log on to https://technet.microsoft.com/en-us/library/aa996719(v=exchg.160).aspx.
This book is for administrators with a basic or limited understanding of Windows PowerShell and who want to increase their skill set in managing both the Exchange On Premise and Online environments.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
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 at www.packtpub.com/authors.
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.
You can download the example code files for this book 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.
You can download the code files by following these steps:
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MicrosoftExchangeServerPowerShellEssentials_ColoredImages.pdf.
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 could 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/submit-errata, 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 to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted 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 <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
This chapter will provide introduction to Windows PowerShell that is required for the rest of the chapters of this book. You will learn about the usage of Windows PowerShell cmdlets, variables, arrays, and loops. You will also learn the use of the PowerShell Help system. We will cover the concept of filtering and exporting objects using pipelines and the usage of loops and conditional statements. This chapter will create a foundation, and we will use subsequent chapters to build this foundation.
The following topics will be discussed in this chapter:
Windows PowerShell is the evolution of the Windows command-line shell, which provides a scripting environment for MS-DOS and the Windows operating system. In MS-DOS and Windows 9X, the shell was command.com, and it was cmd.exe for Windows NT family of the operating system. In the UNIX world, there are different shells such as SH, KSH, CSH, and BASH.
Almost all of these shells provide an environment to execute a command or utility and present the output as text. These shells have some built-in commands such as dir in cmd.exe in Windows NT or later versions, but these built-in commands are limited; and hence, new utilities are written to fill the gap. Shells supported the use of a scripting language (batch files) to automate tasks. There were limitations when it came to creating complex scripts and automating all other aspects provided by a Graphical User Interface (GUI) as equivalent commands are not exposed and the scripting language was basic.
Windows scripting host (Wscript.exe) and its command-line counterpart called Cscript.exe was introduced in 1998 with the release of Windows 98 to address some of the challenges. It is a language-independent scripting environment and allows scripts written in Jscript and VBScript using the APIs exposed by applications. There were deficiencies in this scripting environment due to limited documentation and interoperability issues with shell and security vulnerabilities. There were several security breaches as computer viruses exploited features provided by WSH. There were a few other attempts made by Microsoft to build utilities for specific purpose—for example, netsh—with their list of supported command sets, but they were not integrated with the shell and were inoperable.
In 2005, Microsoft released a new shell called Monad (also known as Microsoft Shell(MSH)), which is designed to automate a wide range of administrative tasks and is based on a new design as opposed to its predecessors.
Similar to the command.com and cmd.exe shells, Windows PowerShell can run three types of programs: built-in commands, external programs, and scripts. However, unlike a command shell, the built-in commands are not embedded into the shell environment but are available as modules in one or more .DLL files. This allows both Microsoft and vendors to write custom modules to manage their applications using PowerShell. Now, most of Microsoft and vendor's applications support management through Windows PowerShell, for example, Windows Server, Exchange Server, SharePoint, Lync Server/Skype for business, and VMWare.
Windows PowerShell is different than its predecessors in the following ways:
With the release of PowerShell 2.0, some APIs (application programming interface) were released that could be used to invoke PowerShell commands right from within your applications. Applications can then use certain PowerShell commands to perform a specific operation, which earlier could only be performed by GUI.
Starting from Exchange Server 2007, this capability has been used to its best advantage as will be explained over the course of the book. Learning PowerShell will help you in managing Microsoft, vendor applications, and services that support PowerShell. It will provide you the skillset required to manage and automate different aspects of Microsoft cloud-based offerings such as Office 365 and Windows Azure. Both of these support PowerShell and have specific modules for management. However, our focus in this book will be on managing Exchange through Windows PowerShell. At times, GUI is strictly used for illustration.
If you are interested in a .Net development, you can write your own cmdlet (pronounced as command-lets) in PowerShell that will perform a specific operation. For this, you will need PowerShell 2.0 Software Development Kit (SDK) and Visual Studio Express Edition. Both of these are free downloads.
You can download the example code files for this book 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.
The following table summarizes the history of the different versions of Windows PowerShell:
Version
Year released
Operating systems
Features
1
2006
Windows Server 2003, Windows Server 2008, Windows XP SP2, and Windows Vista
First release
2
2009
Windows XP SP3, Windows Server 2003 SP2, Windows Vista SP1, Windows Server 2008 R2, and Windows 7
Remoting, Eventing, jobs, modules, ISE, and Exception handling
3
2012
Windows Server 2012 and Windows 8
Session connectivity, Scheduled jobs, update-help, and resumable sessions
4
2013
Windows Server 2012 R2, Windows 8.1, Windows 7 SP1, Windows Server 2008 R2 SP1, and Windows Server 2012
Desired State Configuration, Enhanced debugging, exportable help, and network diagnostics
5.0
2015
In Public Preview at the time of writing this book
OneGet, PowerShellGet, class definitions, and switch management improvements
Windows PowerShell uses a verb-noun pair as a naming system. The name of each cmdlet includes a standard verb hyphenated with a specific noun. Verbs are used for specific actions in Windows PowerShell, and nouns are used to describe objects by users and system administrators. Here are some of the examples that show how little effort is required to work with cmdlets, and one does not have to memorize them.
Nouns in a cmdlet describe what the cmdlet will act on. For example, get-process, get-service, stop-process and stop-service. If this is used regularly, one can get to know the standard set of verbs and nouns used in PowerShell. With these verb-noun pair, hundreds of cmdlet names can be remembered and used.
You will be able to recognize the operation performed by a cmdlet by just reading the name as it is mostly apparent about the name used by a new command should relate to the operation. For example, get-computer will give you a list of computers on your network. Get-date and get-time will display the system date and time respectively. Similarly, stop-computer will shut down a computer. Set-date and set-time will set the system's date and time.
Let's look at how to list all the commands that have the particular verbs called Get and Set using Get-command with the –verb parameter. The output of this command is piped to display in a table format (more on this will be covered later in the Usage of pipelines section).
In the next example, we will just use instead of a format table:
Now, let's use the -Noun parameter, and we will find a list of commands that affect the same object type. For example, if you want to see commands that are available for managing computers, type the following command:
Traditionally, the commands in the earlier shells usually do not have a consistent parameter name. Sometimes, they don't have a name at all, and even if they do, they are abbreviated to make typing easier. But, this makes it difficult for new users to understand the parameters that are used. In Windows PowerShell, consistency is encouraged by using developer guidance on the usage of parameter names.
The names of the parameters in Windows PowerShell have a hyphen '-' prepended to them to allow PowerShell to demarcate them as parameters. In the get-command –Noun example, the name of the parameter is Noun and is typed as –Noun.
The cmdlets in Windows PowerShell support several common parameters as the PowerShell engine controls these parameters. So, no matter how they are implemented, they will behave in a similar way. Another way to drive the consistency and learning of Windows PowerShell are some of the common parameters like—Confirm, WhatIf, outvariable, warningaction, warningvariable, debug, and verbose.
This section will cover the use of help in Windows PowerShell. The help topic for a particular command or conceptual help can assist an administrator who is new to Windows PowerShell or using a particular set of cmdlets to understand its syntax and usage.
The -? parameter with a cmdlet will display Windows PowerShell help for the cmdlet:
The Get-Help cmdlet displays help information about PowerShell cmdlets. Some of the examples are discussed as follows.
The following example gives you the help files from the PowerShell help system one page at a time:
If you know the alias of the cmdlet you are trying to get help for, use the —detailed parameter for full help:
If you are not sure of the exact parameter but remember the initial letter, use the following to get help:
This lists all the parameters of the cmdlet get-process:
This provides help with the syntax of the select-object cmdlet:
There are other properties of the help object such as input types, module name, examples, and more. If you are looking to find all the properties and methods of help object type called get-help <cmdlet-name> | get-member, for example, PS C:\> get-help get-Service | get-member.
The transcript feature in PowerShell helps you to record all your cmdlets and activities at the prompt. This feature is not available for use in the PowerShell application during the writing of this book. This will help you capture all the commands and outputs from the commands that appear in the console in a text file that you specify using the start-transcript cmdlet.
The Start-transcript cmdlet initializes a transcript file, and then creates records of all the subsequent actions in the PowerShell session.
The syntax is shown as follows:
Here are some of the important parameters that you should know about the start-transcript cmdlet. To save the transcript file to a specified path, use the –Path parameter. You cannot use wildcards when you set the path, but you can also use variables. The directories in the path must exist or the command will fail.
The default behavior of the Start-Transcript cmdlet is to overwrite any file that is in the transcript path unless the –noClobber parameter is specified, which prevents Windows PowerShell from overwriting an existing file.
The –Appendparameter will add the new transcript to the end of an existing file. For example, take a look at the following:
When you want to stop recording the transcript, you can either exit the console or type Stop-transcript. The Stop-Transcript cmdlet requires no additional parameters.
The Stop-transcript cmdlet stops recording actions that was started by the start-transcript cmdlet. Use the following syntax:
