One of the great things about Exchange Server is the ability to use PowerShell for a wide variety of administration tasks. And one of the great strengths of PowerShell is the ability to use scripts to automate complex or repetitive tasks to save time, save effort, and avoid errors.

The Exchange Server community has a long history of sharing PowerShell scripts that they have developed so that everyone can benefit from them. Here’s a selection of PowerShell scripts that I think should be in any toolkit.

Note: many of these scripts are developed by individuals in their personal time. If you like a script please let the author know by rating it on the TechNet Script Gallery or leaving a comment on their blog. Similarly, if you find a bug with a script the authors are usually very happy to receive bug reports from the community so that they can fix them.

Exchange Environment Reports

Exchange MVP Steve Goodman wrote this PowerShell script to generate a HTML report that provides an overview of your Exchange environment. I use this script as my first look at any Exchange organization when I am doing support or planning a migration.

Steve’s blog | TechNet Script Gallery

environment-report

Exchange V15 (2013/2016) Unattended Install Script

Installing the Exchange pre-requisites and building Exchange servers from scratch is a good skill to learn, but after you’ve learned it you will want to automate as much of it as possible. Exchange MVP Michel de Rooij has done just that, maintaining this PowerShell script to install pre-requisites and perform unattended installs of Exchange Server 2013 and 2016.

Michel’s blog | TechNet Script Gallery

install-exchange

Exchange Log Level GUI Script

During a troubleshooting exercise there’s a good chance you’ll increase the diagnostic logging level for several Exchange Server components. Zachary Loeber has put together a PowerShell script that launches a GUI to let you configure the diagnostic levels on your servers.

Zachary’s blog | TechNet Script Gallery

log-level-gui

Exchange Mailbox Size and Statistics Report

One of the first PowerShell scripts I wrote many years ago, and have kept updated every since. This script generates a CSV file containing lots of useful stats and information about the mailboxes in your Exchange organization. I use this script when capacity planning and also during migration projects.

Blog post | TechNet Script Gallery

mailbox-report

Health Report for Exchange Server 2010/2013 Environments

This PowerShell script can provide you with a health check report for an Exchange Server 2010 or 2013 environment, highlighting issues such as stopped services, unhealthy database replication, or transport queues not processing messages. Run it as a scheduled task for a quick morning health check delivered straight to your inbox.

Blog post | TechNet Script Gallery

powershell-script-health-check-exchange

Analyze Move Request Performance

During a migration it’s often important to keep an eye on the performance of your migration batches. The Microsoft Exchange Team published this PowerShell script to help you analyze move request performance statistics to identify any causes of poor performance.

Exchange Team blog | TechNet Script Gallery

Monitor Exchange Server Backups

I’ve used this script as a scheduled daily report in every operations role where I was supporting Exchange Server 2007 or later, as well as during every migration project. This script helps you keep an eye on the backup time stamps of Exchange databases to ensure that backups are actually running and completing successfully. Don’t trust your backup software to always tell you the truth, and don’t trust others to always add new databases to the backup schedule when they’re created!

Blog post | TechNet Script Gallery

get-dailybackupalerts-report

Compress and Archive IIS Logs

Keep your disk space utilization under control by regularly compressing and archiving the IIS logs on your Exchange Servers.

Blog post | TechNet Script Gallery

Purge Exchange Server 2013 Log Files

If you’d prefer to just purge the log files completely try Thomas Stensitzki’s update to Brian C Reid’s script that removes not only the IIS logs but also the performance and diagnostic logs that Exchange Server 2013 generates automatically.

Brian’s blog | Thomas’ blog | TechNet Script Gallery

Check Your RBAC Role Group Membership

Keeping a close eye on role group membership in an Exchange environment is important to maintain least-privilege access for the different teams in your organization. This PowerShell script will export the membership of each role group so you can verify who has access to what, and extra info such as whether they have any passwords that haven’t been changed in a long time.

Blog post | TechNet Script Gallery

Generate File-System Antivirus Exclusions List for Exchange Server 2013

Antivirus software is a leading cause of unplanned database failovers in an Exchange environment. This PowerShell script generates the list of file, folder and process exclusions to add to the antivirus configuration on an Exchange server, based on Microsoft’s recommended practices.

Blog post | TechNet Script Gallery

exchange-2013-antivirus-exclusions-01

Audit RDP Connections for your Servers

Ever wanted to know who has been logging on to your Exchange servers using RDP? Exchange MVP Mike Crowley has published this script so you can run a report any time you like.

Mike’s blog | TechNet Script Gallery

Check your Exchange Server SSL Certificates

Expiring SSL certificates can cause a lot of problems in your Exchange environment, so it’s a sensible idea to check them as part of your routine maintenance and health checks. I also use this script any time I am auditing a new environment for a troubleshooting case or a migration project.

Blog post | TechNet Script Gallery

exchange-ssl-certificate-report

Report on Mailbox Permissions

I frequently see people looking for scripts to help them gain some visibility of the mailbox permissions in their Exchange organization. Serkan Varoglu has published this PowerShell script that lets you produce a report of the mailbox permissions for a mailbox, a database, or the entire organization.

TechNet Script Gallery

mailbox-permissions

ActiveSync Device Statistics Report

As staff come and go in your organization the Exchange environment tends to accumulate stale mobile devices. This PowerShell script will generate a report of mobile devices that have not synced in a specified number of days. You can also use it to look at details such as which makes and models of mobile devices your users are connecting with. The report is generated in CSV and HTML email formats.

Blog post | TechNet Script Gallery

get-easdevicereport-email

Recipient Address Report

Mike Crowley wrote this script to produce a report of every recipient’s SMTP proxy addresses, which is very useful in a wide range of migration and management scenarios.

Mike’s blog | TechNet Script Gallery

2

Update Calendar Folder Permissions

Exchange MVP Lasse Pettersson takes the guesswork out of whether you need to run Set-Mailboxfolderpermission, Add-Mailboxfolderpermissions, or Remove-Mailboxfolderpermission, by combining it all into one script that lets you add, update or remove permissions on mailbox folders.

Lasse’s blog | TechNet Script Gallery

What’s Missing?

Do you know of a useful PowerShell script that Exchange admins should know about? Feel free to add a comment below.

Note, please don’t paste entire script contents into the comments below. Publish your script to TechNet, Github, or elsewhere if you want to share it with the community.

About the Author

Paul Cunningham

Paul is a former Microsoft MVP for Office Apps and Services. He works as a consultant, writer, and trainer specializing in Office 365 and Exchange Server. Paul no longer writes for Practical365.com.

Comments

  1. Binance clone

    Binance Clone is an Asset trading platform developed by Codono integrated with multi coins and tokens wallet using Coin nodes or even 3rd party wallets Like CryptoApis, and Coinpayments. Also, Our Product enables the fastest Liquidity with multiple Liquidity Providers.

  2. Tauseef Ansari (India)

    Hey Paul,
    First of all I would like to thank you for Amazing scripts on various exchange tasks.
    I am working on a requirement on Exchange 2013 and 2019 Infra coexistence environment wherein I need to collect logs from EWS IIS and SMTP Protocol logs.

    Ask is:
    Create a PowerShell function to collect logs depending on Date and Keywords inputs, Like I will take the input from user as:
    -Date
    -IP or -Username or -EmailAddress
    -EWS or -IIS -or -SMTPProtocolLogs or -MessageTrackingLogs

    Depending on the date input it should go inside the Logs directory (For IIS) and get the Logs and put them on a CSV file for review.

  3. Patrick Galvin

    Where did the scripts to put servers in and out of Maintenance Mode go?

  4. Saja AbuGharbieh

    if can add script for Database leveling to be equal will be great

    since some Application will create Mailboxes in only One Data base

  5. Nathan Goss

    Hey Paul,

    Do you know if there is a way to clear out the MAPI sessions for a user using a script?

    Thanks,

    Nathan

  6. Tony Phan

    Please help on a scrip that can be used to check each user mailbox and output if there is a rule that forwards externally, need it on Exchange 2016.

  7. Jesus

    Hi Paul!
    I am looking for a way to know through the script to which CAS the user / users is connected, I suppose that by reviewing the IIS records … We have a client disconnection problem and we must pull the thread … 🙂

  8. St. Schenk

    Hi Paul,

    some very nice scripts. 🙂

    I’m searching a script which is telling me, how many contacts are inside a users mailbox.
    We had a sync problem and as result some users have many duplicated contacts, 50000 instead of 1500.

    Stefan

  9. Manuel

    Excellent Scripts

    Thanks Paul & guys

    KUDOS

  10. Bruno Martins

    Hi guys,

    What about scripts to get top senders/recipients?
    And getting an user list of connected users per protocol?

    I think they are missing and are very requested.

    Keep up the good work.

    Cheers!

  11. abdo

    can you help me to get reports for CPU and RAM

  12. Adrian

    Hi Paul.

    I’ve been searching, without success, for a script similar to the one that shows the mailbox permissions (Full Access, Send As and Send on behalf), but to show the Delegate/FolderPermissions.

    I know the shell commands to get the permissions, but just with the results in Format-List/Table.
    It’s been too many years since I touched development or even html.

    Any chance you have a script for this that reports in HTML?

    Thank you.

  13. Sanjit

    Excellent scripts…very useful stuff!!!

  14. Sanjit Sahu

    Excellent scripts…very useful stuff!!!

  15. Quentin Gurney

    I’d like a script that would look at meeting rooms, identify all the organizers, then look in AD to see if the user was disabled or no longer with the company. Step 2 would be to be able to selectively delete them. That way you would not have phantom meetings clogging up your calendar.

  16. Sunil

    Thanks Paul for the scripts.

  17. Joseph

    Hi Paul, Great stuff here! 🙂 Regarding the Exchange Environment Script, is there a way to get OS Version and Service Pack information as well for the Edge Servers? I’m getting errors since these are located in DMZ. Thanks!

  18. Jay

    Hi, I love the script, works wonders. However, we don’t use Public Folders in our environment and was wondering if I could comment out or remove that from the script, which would help it run faster as well. Any suggestions? Thanks

    1. Avatar photo
      Paul Cunningham

      I don’t know which script you’re referring to, but generally speaking yes you can edit the scripts to suit your requirements.

      1. Donny Forbes

        Hi Paul I am trying to use the Get-ExchangeEnviromentReport script as a schedule task, but it doesn’t seem to run. I can run the script from my exchange powershell, but just not as a task. Is there a way or can you tell me what to add to invoke the powershell.exe in the script? Please advise.

      2. Donny Forbes

        Paul I got this to work. I wish there was a nice way to show all the mailboxes like in exchange 2007. It had a colorful graphical report also in html that showed all users mailboxes and all the information related to it.

        1. Avatar photo
          Paul Cunningham

          If you have feedback for Steve about his script by all means go and let him know at his blog, I’m sure he will appreciate it.

  19. Ron

    Good compilation; I seek knowledge around 2 areas I’ve not seen others script nor do you have on the list! 1.) How to create custom folders in Exchange 2013/2016 user mailboxes? 2.) How to Assign Custom Retention Policy Tags to the newly created custom folders?

    The Below 2 links i’ve cobbled together to use EWS APIs and more complicated methods with lots of time… Anyone else covered this ground before? I can get folders created, but cannot get policies assigned. Sheesh, this was WAY easier in Exchange 07 Managed folders…

    https://blogs.msdn.microsoft.com/emeamsgdev/2013/10/20/powershell-create-folders-in-users-mailboxes/

    .Create-Folders.ps1 upn@suffix.local “E-Mail Retention” -ParentFolder “” -EwsManagedApiPath “c:Program FilesMicrosoftExchange ServerV15BinMicrosoft.Exchange.WebServices.dll”

    .Create-Folders.ps1 upn@suffix.local “Keep for 4 years;Keep for 6 years;Keep for 10 years;Keep FOREVER” -ParentFolder “E-Mail Retention” -EwsManagedApiPath “c:Program FilesMicrosoftExchange ServerV15BinMicrosoft.Exchange.WebServices.dll”

    https://blogs.msdn.microsoft.com/emeamsgdev/2016/04/22/powershell-apply-retention-policies-or-auto-archive-settings-to-inbox-sub-folders/

    Any insight would be greatly appreciated and may help your Toolkit.
    -Ron

  20. Umer

    Thank you Paul ! Really useful

  21. Ta Vu

    Very useful. Thanks for your shared.

  22. Matt

    Instead of testing the mapi connectivity of all your mailbox servers one time, does anyone know how to measure the load of mapi connectivity on all your mailbox servers over a period (eg 24hrs)?
    Thanks.

  23. Chris

    *a script

  24. Chris

    @Paul, thank you for your help.

    I’m looking for an script to export a Exchange Online mailbox into PST using remote sessions in powershell, but as far as I know, there’s no nnew-mailboxexportrequest anymore… any help?

    Thanks,

    1. Avatar photo
      Paul Cunningham

      In EXO you can do a discovery search for all contents of a mailbox, and then download the search results as a PST.

  25. Jaro Corbett Abraham

    Thanks for the helpful share.

  26. Michal Ziemba

    @Paul: great summary and we all really appreciate your engagement in sharing your tools with the rest of community for a long time.

    As Thomas Oates pointed OOO, I got a script where you can list all users with currently active Autoreply. This might be an idea to rebuild it adding some more features and using your perfectionism in reports and add yet another script to your gallery.

  27. Mustafa

    Thank you for helping us .. really thank you

  28. Ian

    Excellent sharing. This blog give me a great help. I’m your fan now.

  29. Ken

    Great list, funny thing is, I use most of these scripts on a daily basis. Took me a few years to find them all as needs arose though.

  30. Thomas Oates

    We have a useful Powershell script for setting out of office greetings. Very handy when someone leaves on vacation and forgets to set one. Medical leave, account terminations, etc. especially if you work in an environment where you need legal and/or HR to approve accessing a mailbox. Powershell allows you to set the OOO greeting without actually opening the mailbox with Outlook or OWA.

    1. Carol Ostos

      Sounds good. Care sharing? Thank you!

    2. Claudio

      yeah sound real nice

      1. Riaan Connoway

        Something similar to (users.txt with a list of users) :

        import-csv users.txt | foreach {
        $CustomMessage = “I am on Leave…. Whooohooooo”
        $CustomMessage1 = “I am on Leave…. Whooohooooo”
        Set-MailboxAutoReplyConfiguration $_.alias -AutoReplyState enabled -InternalMessage $CustomMessage -ExternalMessage $CustomMessage1
        }

  31. TomR

    Great stuff ! ???

  32. Turbomcp

    awesome stuff
    Thanks for putting it together into essential list

  33. Rogelio

    Hi Paul, excellent thanks again for this scripts

    1. Robert Stewart

      Paul Cunningham
      do you have any scripts to list the users names from an AD group and then get their remote mailbox and apply limits to the mailbox of that user for number of email Limit the number of recipients when sending email

Leave a Reply