• Home
  • Topics
    • Office 365
    • Teams
    • SharePoint
    • Exchange 2019
    • Exchange 2016
    • Exchange 2013
    • Hybrid
    • Certificates
    • PowerShell
    • Migration
    • Security
    • Azure
  • Blog
  • Podcast
  • Webinars
  • Books
  • About
  • Subscribe
    • Facebook
    • Twitter
    • RSS
    • YouTube

Practical 365

You are here: Home / Exchange Server / PowerShell Scripts for Your Exchange Server Toolkit

PowerShell Scripts for Your Exchange Server Toolkit

September 4, 2015 by Paul Cunningham 50 Comments

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.

Exchange Server Exchange 2010, Exchange 2013, Exchange 2016, PowerShell, Scripts

Comments

  1. Nathan Goss says

    October 13, 2020 at 8:41 am

    Hey Paul,

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

    Thanks,

    Nathan

    Reply
  2. Tony Phan says

    September 14, 2019 at 6:44 am

    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.

    Reply
  3. Jesus says

    September 13, 2019 at 10:04 pm

    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 … 🙂

    Reply
  4. St. Schenk says

    March 14, 2019 at 11:24 pm

    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

    Reply
  5. Manuel says

    March 1, 2018 at 5:25 pm

    Excellent Scripts

    Thanks Paul & guys

    KUDOS

    Reply
  6. Zoltan Erszenyi says

    December 25, 2017 at 9:05 pm

    Paul,

    Another goodie that will make folks’ life easier – assign/remove O365 licenses in bulk:

    http://ezoltan.blogspot.com/2017/12/assign-or-remove-o365-licenses.html

    Zoltan

    Reply
  7. Zoltan Erszenyi says

    December 25, 2017 at 9:02 pm

    Hey Paul,

    This can come handy – setting/resetting the maximum mailbox database size:

    http://ezoltan.blogspot.com/2016/06/get-or-set-mailbox-database-maximum-size.html

    Cheers,
    Zoltan

    Reply
  8. Bruno Martins says

    September 7, 2017 at 7:49 am

    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!

    Reply
  9. abdo says

    July 27, 2017 at 12:22 am

    can you help me to get reports for CPU and RAM

    Reply
  10. Dima Razborov says

    July 10, 2017 at 10:07 pm

    Hey Paul, this is another nice one
    https://blogs.technet.microsoft.com/exchange/2015/04/27/generating-user-message-profiles-for-use-with-the-exchange-calculators/

    Reply
  11. Adrian says

    May 26, 2017 at 10:34 am

    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.

    Reply
  12. Sanjit says

    April 25, 2017 at 5:19 am

    Excellent scripts…very useful stuff!!!

    Reply
  13. Sanjit Sahu says

    April 25, 2017 at 5:17 am

    Excellent scripts…very useful stuff!!!

    Reply
  14. Quentin Gurney says

    February 23, 2017 at 7:09 am

    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.

    Reply
    • Paul Cunningham says

      February 23, 2017 at 8:45 am

      That sounds like a useful script.

      Reply
  15. Sunil says

    January 17, 2017 at 7:56 pm

    Thanks Paul for the scripts.

    Reply
  16. Joseph says

    December 29, 2016 at 2:32 pm

    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!

    Reply
  17. Jay says

    October 14, 2016 at 5:46 am

    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

    Reply
    • Paul Cunningham says

      October 16, 2016 at 10:42 pm

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

      Reply
      • Donny Forbes says

        February 25, 2017 at 1:34 am

        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.

        Reply
      • Donny Forbes says

        February 25, 2017 at 2:07 am

        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.

        Reply
        • Paul Cunningham says

          February 26, 2017 at 4:30 pm

          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.

          Reply
  18. Ron says

    July 20, 2016 at 2:11 am

    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

    Reply
  19. Umer says

    June 27, 2016 at 3:05 pm

    Thank you Paul ! Really useful

    Reply
  20. Ta Vu says

    May 19, 2016 at 2:19 pm

    Very useful. Thanks for your shared.

    Reply
  21. Matt says

    April 22, 2016 at 11:53 pm

    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.

    Reply
  22. Chris says

    March 23, 2016 at 1:58 am

    *a script

    Reply
  23. Chris says

    March 23, 2016 at 1:55 am

    @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,

    Reply
    • Paul Cunningham says

      March 23, 2016 at 1:59 pm

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

      Reply
  24. Jordan says

    March 11, 2016 at 1:50 am

    Hi,

    Thanks for sharing, I will add them to my collection 🙂

    One not mentionned that I use all the time is the DAG database failover script notification.

    This one was created by Nuno Mota and can be found here : https://social.technet.microsoft.com/Forums/en-US/5ed47ca6-55c9-4e01-8aa7-876486e5c89a/exchange-2010-failover-scipt-notification?forum=exchange2010

    Reply
  25. Jaro Corbett Abraham says

    November 18, 2015 at 5:24 pm

    Thanks for the helpful share.

    Reply
  26. Michal Ziemba says

    November 4, 2015 at 10:57 pm

    @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.

    Reply
  27. Mustafa says

    October 24, 2015 at 11:00 pm

    Thank you for helping us .. really thank you

    Reply
  28. Ian says

    September 22, 2015 at 12:56 am

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

    Reply
  29. Colin Giles says

    September 15, 2015 at 1:16 am

    Another Exchange environment report is Exchange 2010 Architecture Report V2, it generate a HTML report that provides an overview of your Exchange environment.

    https://gallery.technet.microsoft.com/scriptcenter/Exchange-2010-Architecture-9368ff56#content

    Reply
    • Pascal says

      September 23, 2015 at 5:19 pm

      Thank you Colin,

      With Franck, we developed another Exchange 2010 Report, with more option.

      https://gallery.technet.microsoft.com/office/Reporting-Exchange-2010-521cfdc0

      and I must publish a report for Exchange 2013.

      Regards.

      Reply
  30. Ken says

    September 11, 2015 at 8:37 pm

    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.

    Reply
  31. Thomas Oates says

    September 8, 2015 at 1:26 am

    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.

    Reply
    • Carol Ostos says

      September 8, 2015 at 7:48 am

      Sounds good. Care sharing? Thank you!

      Reply
    • Claudio says

      September 10, 2015 at 11:15 pm

      yeah sound real nice

      Reply
      • Riaan Connoway says

        September 11, 2015 at 5:46 pm

        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
        }

        Reply
  32. TomR says

    September 8, 2015 at 12:32 am

    Great stuff ! ???

    Reply
  33. Nawar Aljanabi says

    September 7, 2015 at 9:36 pm

    I would add

    Admin Audit logs
    http://mikepfeiffer.net/2010/08/administrator-audit-log-reports-in-html-format-exchange-2010-sp1/

    Mailbox Audit logs
    Generate HTML Report for Mailbox Audit Logs
    https://gallery.technet.microsoft.com/office/Generate-HTML-Report-for-f30f66f3

    Reply
  34. Mohamed Ramadan says

    September 6, 2015 at 8:12 pm

    Hi Paul… Amazing post as always… making admins life easier 🙂

    You could add :
    -MFCMAPI http://mfcmapi.codeplex.com/releases/view/104434
    -Log parser Studio 2.0 http://gallery.technet.microsoft.com/Log-Parser-Studio-cd458765

    Reply
  35. Turbomcp says

    September 5, 2015 at 12:15 am

    awesome stuff
    Thanks for putting it together into essential list

    Reply
  36. Rogelio says

    September 4, 2015 at 11:14 pm

    Hi Paul, excellent thanks again for this scripts

    Reply
    • Robert Stewart says

      December 6, 2018 at 2:25 am

      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

      Reply

Leave a Reply Cancel reply

You have to agree to the comment policy.

Recent Articles

  • The Practical 365 Weekly Update: S2, Ep 9 – Controversial Teams guest changes and a roundup of important Microsoft 365 announcements and features
  • Hands-on SharePoint Syntex Blog Series – Part I
  • The Practical 365 Weekly Update: S2, Ep 8 – What to expect in 2021, Solarigate, TLS in Exchange and new Teams updates
  • Security updates released for Exchange and SharePoint Servers 2010 to 2019
  • The Practical 365 Weekly Update: S2, Ep 7 – Urgent Exchange security updates, new Teams features launch
Practical 365

Related Posts

Related Posts

Training Courses

  • Configuring and Managing Office 365 Security
  • Office 365 Admin Playbook
  • Exchange 2016 Exam 70-345
  • Managing Exchange Mailboxes and Distribution Groups in PowerShell
  • More Training Courses...

Recommended Resources

  • Office 365 Security Resources
  • Office 365 Books
  • Exchange Server Books
  • Exchange Server Migrations
  • Exchange Analyzer
  • Digicert SSL Certificates

About This Site

Practical 365 is a leading site for Office 365 and Exchange Server news, tips and tutorials. Read more...

Find out more about advertising with us.

Contact us


Subscribe to our newsletter
  • Facebook
  • Twitter
  • RSS
  • YouTube

Copyright © 2021 Quadrotech Solutions AG · Disclosure · Privacy Policy
Alpenstrasse 15, 6304 Zug, Switzerland