You are previewing Microsoft Exchange Server 2013 PowerShell Cookbook - Second Edition.
O'Reilly logo
Microsoft Exchange Server 2013 PowerShell Cookbook - Second Edition

Book Description

Benefit from over 120 recipes that tackle the everyday issues that arise with Microsoft Exchange Server. Using PowerShell you’ll learn to add scripts that provide new functions and efficiencies. Only basic knowledge required.

  • Newly updated and improved for Exchange Server 2013 and PowerShell 3

  • Learn how to write scripts and functions, schedule scripts to run automatically, and generate complex reports with PowerShell

  • Manage and automate every element of Exchange Server 2013 with PowerShell such as mailboxes, distribution groups, and address lists

  • In Detail

    Microsoft Exchange Server 2013 is a complex messaging system. Windows PowerShell 3 can be used in conjunction with Exchange Server 2013 to automate and manage routine and complex tasks to save time, money, and eliminate errors.

    Microsoft Exchange Server 2013 PowerShell Cookbook: Second Edition offers more than 120 recipes and solutions to everyday problems and tasks encountered in the management and administration of Exchange Server. If you want to write scripts that help you create mailboxes, monitor server resources, and generate detailed reports, then this Cookbook is for you.

    This practical guide to Powershell and Exchange Server 2013 will help you automate and manage time-consuming and reoccurring tasks quickly and efficiently. Starting by going through key PowerShell concepts and the Exchange Management Shell, this book will get you automating tasks that used to take hours in no time.

    With practical recipes on the management of recipients and mailboxes as well as distribution groups and address lists, this book will save you countless hours on repetitive tasks. Diving deeper, you will then manage your mailbox database, client access, and your transport servers with simple but effective scripts.

    This book finishes with advanced recipes on Exchange Server problems such as server monitoring as well as maintaining high availability and security. If you want to control every aspect of Exchange Server 2013 and learn how to save time with PowerShell, then this cookbook is for you.

    Table of Contents

    1. Microsoft Exchange Server 2013 PowerShell Cookbook
      1. Table of Contents
      2. Microsoft Exchange Server 2013 PowerShell Cookbook
      3. Credits
      4. About the Authors
      5. Acknowledgement
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
          3. Instant Updates on New Packt Books
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. 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. Understanding the pipeline
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. 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
        6. Formatting output
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        7. Working with arrays and hash tables
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        8. Looping through items
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        9. Creating and running scripts
          1. How to do it...
          2. How it works...
          3. There's more…
            1. Execution policy
          4. See also
        10. Using flow control statements
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Creating custom objects
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Watch out for concurrent pipeline errors
          4. See also
        12. Creating PowerShell functions
          1. How to do it...
          2. How it works...
          3. There's more…
            1. Taking it a step further
          4. See also
        13. Setting up a profile
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
      10. 2. 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. Transferring files through remote shell connections
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. Dealing with concurrent pipelines in remote PowerShell
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        6. Managing domains or an entire forest using recipient scope
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Exporting reports to text and CSV files
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        8. Sending SMTP e-mails 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
        9. Scheduling scripts to run at a later time
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Logging shell sessions to a transcript
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. 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
        12. Scripting an Exchange server installation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      11. 3. Managing Recipients
        1. Introduction
          1. Performing some basic steps
        2. Adding, 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. 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
        8. Adding and removing recipient e-mail addresses
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        9. Hiding recipients from address lists
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Configuring recipient moderation
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Configuring message delivery restrictions
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        12. Managing automatic replies and out of office settings for a user
          1. How to do it...
          2. How it works...
          3. There's more...
        13. Adding, modifying, and removing server-side inbox rules
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        14. Managing mailbox folder permissions
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        15. 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
      12. 4. Managing Mailboxes
        1. Introduction
          1. Performing some basic steps
        2. Reporting on the mailbox size
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Working with move requests and performing mailbox moves
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Removing the move requests
            2. Moving the archive mailboxes
            3. Moving the mailboxes in batches
            4. Moving mailboxes with corrupt items
          4. See also
        4. Mailbox move e-mail notification
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        5. 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
        6. Deleting messages from mailboxes
          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
        7. Managing disconnected mailboxes
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        8. Generating mailbox folder reports
          1. How to do it...
          2. How it works...
          3. There's more…
            1. Taking it a step further
          4. See also
        9. Reporting on mailbox creation time
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Checking mailbox logon statistics
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Setting storage quotas for mailboxes
          1. How to do it...
          2. How it works...
          3. There's more...
        12. Finding inactive mailboxes
          1. How to do it...
          2. How it works...
          3. There's more...
        13. Detecting and fixing corrupt mailboxes
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        14. Restoring deleted items from mailboxes
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        15. Managing public folder mailboxes
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        16. Reporting on public folder statistics
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        17. Managing user access to public folders
          1. How to do it...
          2. How it works...
          3. There's more…
      13. 5. 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. Excluding hidden recipients from a dynamic distribution group
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        6. Converting and upgrading distribution groups
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        7. Allowing managers to modify group membership
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        8. Removing disabled user accounts from distribution groups
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        9. Working with distribution group naming policies
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Working with distribution group membership approval
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Creating address lists
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        12. Exporting address list membership to a CSV file
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        13. Configuring hierarchical address books
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      14. 6. 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
      15. 7. 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
      16. 8. Managing Transport Service
        1. Introduction
          1. Performing some basic steps
        2. Managing connectors
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        3. Configuring transport limits
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        4. Allowing application servers to relay mail
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        5. Managing transport rules and settings
          1. How to do it...
          2. How it works...
          3. There's more…
            1. Modifying transport rules
            2. Enabling, disabling, and removing transport rules
            3. Protecting data from leaving the organization
        6. Creating a basic disclaimer
          1. How to do it...
          2. How it works...
          3. See also
        7. Working with custom DSN messages
          1. How to do it...
          2. How it works...
          3. There's more…
        8. Managing connectivity and protocol logs
          1. How to do it...
          2. How it works...
          3. There's more…
            1. Parsing logfiles
        9. 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
        10. Working with messages in transport queues
          1. How to do it...
          2. How it works...
          3. There's more…
        11. Searching anti-spam agent logs
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        12. Implementing a header firewall
          1. How to do it...
          2. How it works...
          3. There's more...
      17. 9. High Availability
        1. Introduction
          1. Performing some basic steps
        2. Building a Windows NLB cluster for CAS servers
          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
        3. Creating a Database Availability Group
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        4. Adding mailbox servers to a Database Availability Group
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        5. 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
        6. Adding mailbox copies to a Database Availability Group
          1. How to do it...
          2. How it works...
          3. There's more…
          4. See also
        7. Activating mailbox database copies
          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...
        9. Reseeding a database copy
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Using the automatic reseed feature
          1. How to do it...
          2. How it works...
          3. See also
        11. Performing maintenance on Database Availability Group members
          1. How to do it...
          2. How it works...
          3. There's more...
        12. 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
      18. 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 e-mail messages as another user or group
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Working with Role Based Access Control (RBAC)
          1. How to do it...
          2. How it works...
          3. There's more...
            1. RBAC is for end users too
          4. See also
        6. Creating a custom RBAC role for administrators
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        7. Creating a custom RBAC role for end users
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        8. Troubleshooting Role Based Access Control
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        9. Generating a certificate request
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Installing certificates and enabling services
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Importing certificates on multiple exchange servers
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      19. 11. Compliance and Audit Logging
        1. Introduction
          1. Performing some basic steps
        2. Managing archive mailboxes
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Configuring archive mailbox quotas
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        4. 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
        5. Applying retention policies to mailboxes
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        6. Placing mailboxes on retention hold
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        7. Placing mailboxes on in-place hold
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        8. Performing a discovery search
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        9. Enabling mailbox audit logging
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        10. Generating mailbox audit log reports
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        11. Configuring Administrator Audit Logging
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        12. Searching the administrator audit logs
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      20. 12. Server Monitoring and Troubleshooting
        1. Introduction
          1. Performing some basic steps
        2. Managing and monitoring services
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Verifying server connectivity
          1. How to do it...
          2. How it works...
        4. Working with event logs
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Reporting on disk usage
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        6. Checking CPU utilization
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        7. Monitoring memory utilization
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        8. Reporting on Exchange Server uptime
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        9. Troubleshooting the Mailbox role
          1. How to do it...
          2. How it works...
          3. See also
        10. Troubleshooting the Client Access Server role
          1. How to do it...
          2. How it works...
          3. See also
        11. Troubleshooting the Transport service
          1. How to do it...
          2. How it works...
          3. See also
        12. Verifying certificate health
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
      21. 13. 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...
          4. Certificates matter
        3. Sending e-mail 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 e-mail message
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        7. Deleting e-mail 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
      22. A. 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
      23. B. Query Syntaxes
        1. Advanced Query Syntax
        2. Using the word phrase search
          1. Examples
        3. Using a date range search
          1. Examples
        4. Using the message type search
          1. Examples
        5. Using the logical connector search
          1. Examples
      24. Index