O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Microsoft Exchange Server 2016 PowerShell Cookbook - Fourth Edition

Book Description

Make the most of PowerShell's features to manage all aspects of your Exchange Server 2016 environment.

About This Book

  • Learn to integrate PowerShell with Exchange Server 2016
  • Write scripts and functions to run tasks automatically, and generate complex reports with PowerShell
  • Use these effective recipes to learn all popular and important PowersShell scripts to manage tasks and avoid errors

Who This Book Is For

This book is for messaging professionals who want to build real-world scripts with Windows PowerShell and the Exchange Management Shell. You'll also find it indispensable if you're a network or systems administrator responsible for managing and maintaining Exchange Server 2016.

What You Will Learn

  • Master the new features and capabilities of PowerShell and Exchange Server 2016
  • Get to grips with the core PowerShell concepts
  • Use simple PowerShell scripts and commands to get powerful results
  • Generate detailed reports, send the output of commands by email , and schedule scripts to run automatically
  • Import, export, and move mailboxes, and delete messages from mailboxes using the command line
  • Configure transport server settings such as mail relay, tracking logs, transport rules, delivery reports, and more
  • Manage mailbox and public folders
  • Monitor the health of an Exchange environment through built-in cmdlets and other methods
  • Integrate Exchange with Office Online Server, Skype for Business Server, and Exchange Online (Office 365)

In Detail

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.

Style and approach

This practical guide is packed with handy recipes to help you perform common administration tasks, as well as complex tasks in Exchange Server, without any hassle.

Downloading the example code for this book. 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 code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. PowerShell Key Concepts
    1. Introduction
      1. Performing some basic steps
    2. Using the help system
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Getting help with cmdlets and functions
      4. See also
    3. Understanding command syntax and parameters
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Command aliases
      1. How to do it...
      2. How it works...
      3. See also
    5. Setting up a PowerShell profile
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Understanding the pipeline
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Working with variables and objects
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Variable expansion in strings
        2. Strongly typed variables
    8. Working with arrays and hash tables
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Looping through items
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Creating custom objects
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. Using debugger functions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Understanding the new execution policy
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Using the Save-Help function
      1. How to do it...
      2. How it works...
      3. See also
    14. Working with script repositories
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  3. Exchange Management Shell Common Tasks
    1. Introduction
      1. Performing some basic steps
    2. Manually configuring remote PowerShell connections
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Using explicit credentials with PowerShell cmdlets
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Transferring files through remote shell connections
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Managing domains or an entire forest using a recipient scope
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Exporting reports to text and CSV files
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Sending SMTP emails through PowerShell
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Sending messages with attachments
        2. Sending command output in the body of a message
      4. See also
    8. Scheduling scripts to run at a later time
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Logging shell sessions to a transcript
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Automating tasks with the scripting agent
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Using multiple cmdlets with the OnComplete API
      5. See also
    11. Scripting an Exchange server installation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
  4. Managing Recipients
    1. Introduction
      1. Performing some basic steps
    2. Creating, modifying, and removing mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Setting Active Directory attributes
      4. See also
    3. Working with contacts
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Managing distribution groups
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Managing resource mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Converting mailboxes
      4. See also
    6. Creating recipients in bulk using a CSV file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Taking it a step further
      5. See also
    7. Configuring MailTips
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Working with recipient filters
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Understanding variables in filters
      4. See also
    9. Adding and removing recipient email addresses
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Hiding recipients from address lists
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. Configuring recipient moderation
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Configuring message delivery restrictions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Managing automatic replies and out-of-office settings for a user
      1. How to do it...
      2. How it works...
      3. There's more...
    14. Adding, modifying, and removing server-side inbox rules
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    15. Managing mailbox folder permissions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    16. Importing user photos into Active Directory
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
        1. Taking it a step further
      5. See also
  5. Managing Mailboxes
    1. Introduction
      1. Performing some basic steps
    2. Reporting on mailbox sizes
      1. How to do it...
      2. How it works...
        1. There's more...
      3. See also
    3. Reporting on the mailbox creation time
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Working with move requests and performing mailbox moves
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Removing move requests
        2. Moving archive mailboxes
        3. Moving mailboxes in batches
        4. Moving mailboxes with corrupt items
      4. See also
    5. Email notification on mailbox moves
      1. How to do it...
      2. How it works...
      3. There's more…
      4. See also
    6. Importing and exporting mailboxes
      1. How to do it...
      2. How it works...
      3. There's more…
        1. Importing data into mailboxes
        2. Taking it a step further
      4. See also
    7. Deleting messages from mailboxes using Search-Mailbox
      1. How to do it...
      2. How it works...
      3. There's more…
        1. Running reports before deleting data
        2. Deleting messages in bulk
      4. See also
    8. Deleting messages from mailboxes using Compliance Search
      1. How to do it...
      2. How it works...
      3. See also
    9. Managing disconnected mailboxes
      1. How to do it...
      2. How it works...
      3. There's more…
        1. Purging mailboxes
        2. Cleaning databases
      4. See also
    10. Setting storage quotas for mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. Finding email addresses with numbers
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Finding mailboxes with different SIP and Primary SMTP addresses
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Finding inactive mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    14. Detecting and fixing corrupt mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
    15. Restoring deleted items from mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    16. Managing public folder mailboxes
      1. How to do it...
      2. How it works...
      3. There's more…
        1. Public folder quotas
      4. See also
    17. Reporting on public folder statistics
      1. How to do it...
      2. How it works...
      3. See also
    18. Managing user access to public folders
      1. How to do it...
      2. How it works...
      3. There's more…
      4. See also
  6. Distribution Groups and Address Lists
    1. Introduction
      1. Performing some basic steps
    2. Reporting on distribution group membership
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Adding members to a distribution group from an external file
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Previewing dynamic distribution group membership
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Backing up distribution groups membership
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Excluding hidden recipients from a dynamic distribution group
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Converting and upgrading distribution groups
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Allowing managers to modify group permissions
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Removing disabled users from distribution groups
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Working with distribution group naming policies
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. Working with distribution group membership approval
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Creating address lists
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Exporting address list membership to a CSV file
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    14. Configuring hierarchical address books
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  7. Mailbox Database Management
    1. Introduction
      1. Performing some basic steps
    2. Managing the mailbox databases
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Understanding automatic mailbox distribution
        2. Taking it a step further
      4. See also
    3. Moving databases and logs to another location
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Manually moving databases
        2. Taking it a step further
      4. See also
    4. Configuring the mailbox database limits
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Taking it a step further
      4. See also
    5. Reporting on mailbox database size
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Finding the total number of mailboxes in a database
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Determining the average mailbox size per database
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Reporting on database backup status
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Restoring data from a recovery database
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Understanding target mailbox identity
        2. Learning about other useful parameters
        3. Understanding mailbox restore request cmdlets
        4. Taking it a step further
      4. See also
  8. Managing Client Access
    1. Introduction
      1. Performing some basic steps
    2. Managing ActiveSync, OWA, POP3, and IMAP4 mailbox settings
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Setting internal and external CAS URLs
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Command syntax for the remaining virtual directories
      4. See also
    4. Managing Outlook Anywhere settings
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Blocking Outlook clients from connecting to Exchange
      1. How to do it...
      2. How it works...
      3. There's more...
    6. Reporting on active OWA and RPC connections
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Controlling ActiveSync device access
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Reporting on ActiveSync devices
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  9. Managing Transport Servers
    1. Introduction
      1. Performing some basic steps
    2. Configuring transport limits
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Managing connectors
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Allowing application servers to relay emails
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Checking if the IP address is in a receive connector
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Comparing receive connectors
      1. How to do it...
      2. How it works...
      3. See also
    7. Adding IP address to receive connectors
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Working with custom DSN messages
      1. How to do it...
      2. How it works...
      3. There's more...
    9. Managing connectivity and protocol logs
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Parsing log files
        2. POP and IMAP logging
    10. Searching message tracking logs
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Taking it a step further
      4. See also
    11. Determining which email client sent an email
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Working with messages in transport queues
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Searching anti-spam agent logs
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    14. Implementing a header firewall
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    15. Configuring the Edge Transport server role
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  10. Exchange Security
    1. Introduction
      1. Performing some basic steps
    2. Granting users full access permissions to mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Finding users with full access to mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Sending email messages as another user or group
      1. How to do it...
      2. How it works...
      3. There's more...
    5. Throttling client connections
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Working with Role Based Access Control
      1. How to do it...
      2. How it works...
      3. There's more...
        1. RBAC for end users
      4. See also
    7. Creating a custom RBAC role for administrators
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Creating a custom RBAC role for end users
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Troubleshooting RBAC
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Generating a certificate request
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. Installing certificates and enabling services
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Importing certificates on multiple Exchange servers
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    13. Configuring Domain Security
      1. How to do it...
      2. How it works...
      3. See also
    14. Configuring S/MIME for OWA
      1. How to do it...
      2. How it works...
      3. See also
    15. Configuring Windows Defender Exclusions
      1. How to do it...
      2. How it works...
      3. There's more...
  11. Compliance and Audit Logging
    1. Introduction
      1. Performing some basic steps
    2. Configuring journaling
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Managing archive mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Configuring archive mailbox quotas
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Creating retention tags and policies
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Understanding default tags
      4. See also
    6. Applying retention policies to mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Placing mailboxes on retention hold
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Placing mailboxes on in-place hold or litigation hold
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Searching and placing a hold on public folders
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    10. Performing eDiscovery searches
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    11. Performing Compliance searches
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    12. Configuring data loss prevention
      1. How to do it...
      2. How it works...
      3. There's more...
    13. Configuring administrator audit logging
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    14. Searching the administrator audit logs
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    15. Configuring mailbox audit logging
      1. How to do it...
      2. How it works...
    16. Searching mailbox audit logs
      1. How to do it...
      2. How it works...
      3. There's more...
  12. High Availability
    1. Introduction
      1. Performing some basic steps
    2. Creating a Database Availability Group
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    3. Adding mailbox servers to a Database Availability Group
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Configuring Database Availability Group network settings
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Renaming and removing DAG networks
        2. Replication compression and encryption
    5. Adding mailbox copies to a Database Availability Group
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Activating mailbox database copies
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Blocking database moves
      4. See also
    7. Reseeding a database copy
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Working with lagged database copies
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Lagged copy play down
    9. Using the automatic reseed feature
      1. How to do it...
      2. How it works...
      3. See also
    10. Performing maintenance on Database Availability Group members
      1. How to do it...
      2. How it works...
      3. There's more...
    11. Reporting on database status, redundancy, and replication
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Understanding switchover and failover metrics
        2. Understanding replication metrics
      4. See also
  13. Monitoring Exchange Health
    1. Introduction
      1. Performing some basic steps
    2. Using Exchange test cmdlets
      1. How to do it...
      2. How it works...
      3. There's more...
    3. Using Health Probe checks
      1. How to do it...
      2. How it works...
      3. There's more...
    4. Checking the server health and health sets
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    5. Monitoring transaction logs
      1. How to do it...
      2. How it works...
    6. Monitoring the disk space
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Checking database redundancy
      1. How to do it...
      2. How it works...
      3. See also
  14. Integration
    1. Introduction
      1. Performing some basic steps
    2. OAuth configuration
      1. How to do it...
      2. How it works...
      3. See also
    3. Configuring Exchange archiving for Skype for Business Server
      1. How to do it...
      2. How it works...
      3. See also
    4. Configuring and enabling the Unified Contact Store
      1. How to do it...
      2. How it works...
      3. See also
    5. Integrating Skype for Business with Outlook on the web
      1. How to do it...
      2. How it works...
      3. See also
    6. Configuring a user with a high-resolution photo
      1. How to do it...
      2. How it works...
      3. See also
    7. Office Online Server integration
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    8. Validating Exchange hybrid
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  15. Scripting with the Exchange Web Services Managed API
    1. Introduction
      1. Performing some basic steps
    2. Getting connected to EWS
      1. How to do it...
      2. How it works...
      3. There's more...
        1. Certificates matter
    3. Sending email messages with EWS
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    4. Working with impersonation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Searching mailboxes
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    6. Retrieving the headers of an email message
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    7. Deleting email items from a mailbox
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    8. Creating calendar items
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
    9. Exporting attachments from a mailbox
      1. How to do it...
      2. How it works...
      3. There's more...
      4. See also
  16. Common Shell Information
    1. Exchange Management Shell reference
      1. Commonly-used shell variables
      2. Commonly-used type accelerators
      3. Scripts available in the $Exscripts directory
    2. Properties that can be used with the -Filter parameter
    3. Properties that can be used with the -RecipientFilter parameter
  17. Query Syntaxes
    1. Using the word phrase search
      1. Examples
    2. Using a date range search
      1. Examples
    3. Using the message type search
      1. Examples
    4. Using search operators
      1. Examples