One of the Exchange Server administration tasks I perform almost every day is creating mailbox size reports. There are a few different reasons that I create these reports, such as planning a mailbox migration project, responding to a storage capacity alert for a particular database, or providing a specific team of people with a report of their mailbox sizes.
Now it is pretty easy to get the sizes for Exchange mailboxes and to handle the formatting of the Exchange 2010 mailbox statistics so that they are easier to perform calculations on, but it gets a bit boring running those commands day after day.
Even worse, after running the commands to create a CSV report I still had to open that in Excel, remove the unwanted details, use Excel formulas to convert the values from bytes to megabytes, sort them into order, and so on. Again not difficult, just boring after doing it hundreds of times.
So I created a PowerShell script, Get-MailboxReport.ps1, to do all of the heavy lifting for me, and I’m sharing that script with you here.
Download the script file here: Get-MailboxReport.ps1 (downloaded 22786 times so far)
Let’s take a look at how the script works. Here is a video to demonstrate:
I’ve included help information within the script itself so you can use Get-Help to discover how to run the script.
[PS] C:\Scripts\demo>Get-Help .\Get-MailboxReport.ps1
NAME
C:\Scripts\demo\Get-MailboxReport.ps1
SYNOPSIS
Get-MailboxReport.ps1 - Mailbox report generation script.
SYNTAX
C:\Scripts\demo\Get-MailboxReport.ps1 [-database ] []
C:\Scripts\demo\Get-MailboxReport.ps1 [-file ] []
C:\Scripts\demo\Get-MailboxReport.ps1 [-server ] []
C:\Scripts\demo\Get-MailboxReport.ps1 [-mailbox ] []
C:\Scripts\demo\Get-MailboxReport.ps1 [-all] []
DESCRIPTION
Generates a report of useful information for
the specified server, database, mailbox or list of mailboxes.
Use only one parameter at a time depending on the scope of
your mailbox report.
RELATED LINKS
For more script details, a video demo, or to give feedback please go to:
http://exchangeserverpro.com/powershell-script-create-mailbox-size-report-exchange-server-2010
REMARKS
To see the examples, type: "get-help C:\Scripts\demo\Get-MailboxReport.ps1 -examples".
For more information, type: "get-help C:\Scripts\demo\Get-MailboxReport.ps1 -detailed".
For technical information, type: "get-help C:\Scripts\demo\Get-MailboxReport.ps1 -full".
Depending on which parameter you use the output will vary.
- If you use the -mailbox parameter to query a single mailbox, then the output will appear in the console window. I don’t really see the need to output a single mailbox’s details to a CSV file.
- If you use any of the other parameters, -server, -database, -file, or -all, the output will be written to a CSV file in the same folder you’re running the script from.
- You can use the optional -filename parameter to specify your own output file name
Once you’ve generated the CSV report you can open it with Excel and begin to analyze the data.
Download the script file here: Get-MailboxReport.ps1 (downloaded 22786 times so far)
Change Log:
- 6/02/2012 – V1.0 – Initial version
- 27/02/2012 – V1.1 - Improved recipient scope settings, exception handling, and custom file name parameter.




This is Awsome. I tried it and works smoothly. Before using this scripte i used to get the results manually by just entering the commands every time.
I have one query about the text file that we need to create for getting the results for particular users. which fileds should i enter in the text file.
Thanks
Devang
Display name, alias, or UPN should work. Take your pick. I usually just use display name.
Hi Paul,
Can u make this script work with server parameter? So it can list all the mailboxes from the server at once.
Thanks,
Sorin.
Sure thing. Actually I’m already working on that, will post an updated when I’ve got it finished.
I’ve managed to do it by myself
and now works with server parameter.
I modified your script and it works perfect.
Many thanks Paul,
Sorin.
I’ve included a -server option in the latest version.
Script has had a major overhaul and re-release, so much so that I’m just going to call this new one V1.0
question. is it possilbe to script a way to find all emails with attachments over 25meg.
thanks
Not with this script, but perhaps with a script that utilizes Exchange Web Services.
thank Paul
if you have time to point me in a direction of how to write that script…that would be great.
this one is really good too.
I haven’t done any EWS script development yet, so I don’t have anything to offer you right now. Although you’re not the first person to ask me for a script like that, so I think its time I started to get into it
But in the meantime, to learn about using EWS the first place I’d go to is Glen Scales’ blog here:
http://gsexdev.blogspot.com.au/
Hi Paul,
That script very useful, very well documented as well. I’ll try to improve it adding if the user has mailbox default storage limits.
Thanks for sharing!
hi
good work paul, thanks for sharing,
Paul
I have an issue where the powershel is preventing my from runnin gthe script. ” the file is not digitally signed” is the complaint from the PS!!
scratch my last post. Its early in the morning here………………
Hi Kevin, try changing your execution policy to unrestricted.
Set-ExecutionPolicy Unrestricted
Keep getting an error ….
“Missing opening “(” after keyword ‘for’.
At C:\Scripts\get-mailboxreport.ps1:48 char:5
+ For m <<<< ore script details, a video demo, or to give feedback please go to:
Am I missing something?
Exch 2007
Hi Josh, it is written for PowerShell v2.0. Try running:
$host
…to see which version you’ve got. If you’re on version1.0 you can try and edit the script to remove all that help info at the start, and see if that works, but I haven’t specifically tested it on v1.0 to check for any other issues.
Excellent script! Thanks for the work and the updates. I know that this will be used much by myself and the consultants I work with.
Thanks again
Getting this error message.
[PS] C:\temp\Exchange\PowerShell\other>.\Get-MailboxReport.ps1 -database MBX1VP\MbxDb-YNHH-002
Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
computer. Do you want to run C:\temp\Exchange\PowerShell\other\Get-MailboxReport.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”): R
Cannot process argument transformation on parameter ‘Database’. Cannot convert value “MBX1VP\MbxDb-YNHH-002″ to type “M
icrosoft.Exchange.Configuration.Tasks.DatabaseIdParameter”. Error: “‘MBX1VP\MbxDb-YNHH-002′ is not a valid value for th
e identity.
Parameter name: Identity”
+ CategoryInfo : InvalidData: (:) [Get-Mailbox], ParameterBindin…mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Mailbox
Which version of Exchange?
Try supplying the -database value as “server\storagegroup\database” if you’re running Ex2007.
Never mind. Got it now. Still getting this message:
Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
computer. Do you want to run C:\temp\Exchange\PowerShell\other\Get-MailboxReport.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”): R
I ran Set-ExecutionPolicy Unrestricted
May also need to right-click the downloaded file, and in properties unblock it.
Paul;
Great script! I removed a few of the output fields (we only have one mail server and one mail database, so those fields weren’t meaningful for us). At the moment I am trying to sort the resulting csv file via the script to put the mailboxes in order largest to smallest. Could use some help getting this to work.
Once I’ve got that figured out, this script is going to save me a ton of time. I’ve got it running as a schedlued task on my exchange server and emailing me the resulting csv on the first of every month.
In the last Else block try adding a Sort-Object to the $report | Export-CSV line like this:
$report | Sort-Object “Size (Mb)” -Desc | Export-Csv -Path $reportfile -NoTypeInformation
how you scheduled this task, please provide the steps.
Thanks
Alagar
I am trying to run this script using the -database or -file parameter and it’s generating a blank csv file. The csv file generated is of 0 bytes.
That will happen if no mailbox info could be retrieved.
For -database make sure you’re supplying a value that would work if you ran “Get-Mailbox -database“.
For -file try removing the -ignoredefaultscope switch from the script line
“if($file) { $mailboxes = @(Get-Content $file | Get-Mailbox -resultsize unlimited -IgnoreDefaultScope) }”
I’ve added some script logic so that instead of creating a 0kb file it will instead show a warning that no mailboxes were found matching the criteria given.
Well, I tested the -database parameter works with .\GetMailboxReport.ps1 -database ‘ServerName\StorageGroupName\DataabaseName’
However, .\GetMailboxReport.ps1 -file does not work. I tried Display Name, Primary SMTP address, UPN but it doesn’t work. It creates a blank 9 byte csv file.
Ah yep, see comment above. Try removing -ignoredefaultscope from the line:
“if($file) { $mailboxes = @(Get-Content $file | Get-Mailbox -resultsize unlimited -IgnoreDefaultScope) }”
I’ll add it to my bug list.
Fantastic! It worked. Great script.
Thanks!
Hi Paul,
Great report for Migrations. As I need the Alias to perform the migration, I have added this in the first column:
$userObj | Add-Member NoteProperty -Name “Alias” -Value $mb.Alias
I also added sort “Size (Mb)” -Desc
I did run this on a combined DC and Exchange 2007 SP3 Server – Enabled and Expires is blank. OK on other Exchange 2007 SP3 Server, so seems issue having DC and Exchange 2007 together..
Could you try commenting out the error suppression lines at the start of the script and see if it produces any errors on the combined DC/Exchange server?
Thanks again paul for an amazing time saver(and also teaches me powershell)
i only had one issue when i ran it through 2010 ps(dont know if it matters) using -file
i got cannot move something about distinguage name cannot be used or must be used:) when using -ignorescope
so i removed the ignorescope for the file part of the script and it ran like a charmer:)
Thanks again
Much appreciated
Yep, little bug I need to work on there. If you have a multi-domain forest you’d just need to put your management shell session into viewentireforest $true mode to see all the mailboxes in the report.
Or if you’re a single domain forest it doesn’t matter, script will work as you’ve modified it
This bug should be fixed now in the latest version (1.1).
Hello Paul,
Thanks again för sharing your script. Works great, I just have a question… How can I do to find the right character in the csv file .. I m having in my exchange swedish names with those: å,ä,ö.
Is it a parameter to add ?
Sorry, I don’t understand the question.
When Im having a look at the csv file after I ran the script,
If for example the name of the user is Åsa Bergström, the result in the csv file is ?sa Bergstr?m
Its not the right character, I would like to get on my csv file the swedish characters like : the å the ä and the Ö instead of “?”
Hope I m more clear now?
Ah, I understand now. Not sure of the solution though, I’ll see if I can find something.
Nice report. I’d like to put it into a scheduled task for a weekly/monthly report that’s emailed to me. I’m wondering how to call upon the output file as it will change each time it’s ran.
Hi Christa, probably two ways you could do that.
1) Remove the file name randomization. So instead of
$reportfile = “MailboxReport-$timestamp-$random.csv”
have simply
$reportfile = “MailboxReport.csv”
2) The file name is stored as $reportfile, so if you’re adding email functionality to the script you can always reference the file name by that variable, no matter what the real name is.
I’ve added a -filename optional parameter to the latest version (1.1) for those who wish to specify the file name instead of the randomly generated ones (actually I use -filename almost every time I run it now
)
I guess I am a retard because I can’t get it to run. I keep getting the following error:
[PS] C:\Windows\system32>c:\scripts\get-Mailboxreport.ps1
The term ‘c:\scripts\get-Mailboxreport.ps1′ is not recognized as the name of a cmdlet, function, script file…..
What am I doing wrong? I am not an expert with PowerShell but this shouldn’t be this hard. thanks
Hi Tom,
Navigate to the folder where you’ve saved the script file, then run it with:
.\Get-Mailboxreport.ps1
You’ll need to supply one of the parameters for which type of report you want to run. You can see the help info by running:
Get-Help .\Get-MailboxReport.ps1
Or watch the video above for a demonstration.
Hope that helps.
I had already tried it that way but I ran it again. See below. I get the same error. It doesn’t seem to matter how I run it. Can you help further? This is driving me nuts. I will watch the video as well.
[PS] C:\scripts>.\Get-MailboxReport.ps1
The term ‘.\Get-MailboxReport.ps1′ is not recognized as the name of a cmdlet, function, script file,…….
thanks
You’ve downloaded the Zip file and extracted the PS1 file to C:\Scripts I take it?
Great script, but I am seeing something odd when I use the -server parameter. The number of mailbox objects listed in the EMC is 2498, but when I use the -server parameter it only processes about 1400 or so, not the full 2498. To get around that for now, I am using a generated user.txt file and using the -file parameter. Any ideas why the difference ?
Thanks
Are all the mailbox users in the same domain in AD, or different domains?
We only have one AD domain.
I recently tried the updated version and that seems to work just fine.
Thanks again
thz a lot fr the script, very useful
FYI I wrote a similar in concept script to generate Exchange 2010 mailbox billing reports in Excel directly. While it is a slightly different focus than what you are doing (in that it grabs all customer mailboxes or specific OUs, not databases or servers), perhaps you could recycle the Execl logic in my script to dump your data directly into Excel spreadsheet where you have already pre-formatted the attributes the way you want (which we also had to do) and save yourself a step or two:
http://gallery.technet.microsoft.com/Exchange-Mailbox-Billing-a33bcbec
I hope it helps.
Thanks for the great script Paul. I’ve removed a few of the objects I don’t need, and plan to schedule this to be exported to a SQL server so we can import the results into a database and report on mailbox growth per user.
I’ve changed your script to remove the random number being added to the file name, but if you can give me some advice on how to alter the export location that would be fantastic as i’d like the file exported to a folder that will have everything in it xcopied to another location at set times.
Eg: C:\ExchangeReportExport
Cheers from Aus, and thanks again Shane.
Oh worked it out…
$reportfile = “C:\PSScripts\Copy\MailboxReport-$timestamp.csv”
easy
Yep, also I’ve added a -filename parameter to the latest version (1.1) just uploaded in the last few minutes if you wanted to grab that. It has a few other minor fixes as well.
thanks so much
works great. What do i need to change the output file name to contain the server name it was run against?
You can use the -filename parameter to specify your own file names.
Thank you for providing us this script, I run it fine from PS command but when I try to run it on a batch file it doesn’t fetch anything. Can you please help with the line to run it on a batch file?
powershell.exe -noexit c:\Temp\Get-MailboxReport.ps1 -all
I get
Collecting mailbox list
Collecting report data
No mailboxes were found matching that criteria.
Getting output below when running the scripts
Collecting mailbox list
Collecting report data
No mailboxes were found matching that criteria.
It’s working now in the batch file, I just added the command to load Exchange Management Shell in the PS script.
Thanks
Hi Paul
How can we use this script and add the User Mailbox Quota in , so that it also shows in the csv file
I have added to following values to show the Storage quotas as well
$userObj | Add-Member NoteProperty -Name “IssueWarningQuota” -Value $mb.IssueWarningQuota.Value.ToMB()
$userObj | Add-Member NoteProperty -Name “ProhibitSendQuota” -Value $mb.ProhibitSendQuota.Value.ToMB()
$userObj | Add-Member NoteProperty -Name “ProhibitSendReceiveQuota” -Value $mb.ProhibitSendReceiveQuota.Value.ToMB()
I have added these as well:
$userObj | Add-Member NoteProperty -Name “Primary SMTP Address” -Value $mb.PrimarySMTPAddress
$userObj | Add-Member NoteProperty -Name “Forwarding Address” -Value $mb.ForwardingAddress
$userObj | Add-Member NoteProperty -Name “Hidden From Address Lists” -Value $mb.HiddenFromAddressListsEnabled
Make sure that in your “Select=-Object” line (154 in the latest version), that you add these attributes into your select statement. For example:
$stats = $mb | Get-MailboxStatistics | Select-Object TotalItemSize,TotalDeletedItemSize,ItemCount,LastLogonTime,LastLoggedOnUserAccount,HiddenFromAddressListsEnabled,ForwardingAddress,PrimarySMTPAddress
Hi ShaunH,
I have added those lines to get storage quota and if I run the script against 1 mailbox, I can see those values but when I run against a database, those values are missing from the export CSV file.
I have also added the values of BR Thurr and they are present in the CSV
Any idea?
Thanks,
Mac
@BKK-Mac
did you get this solved eventually? I`m also having this issue with the script. Can only display it for one user but not for all in Mb.
The issue is the Value.ToMB() setting as when it encounters a mailbox which has no value set this is returned as “Unlimited” which can’t be converted to MB and it causes it to fail.
I got round that by setting up a conditional statement to test if the quota returns a value and attached to a variable and then calling that variable
$ProhibitSendReceiveQuota = if($mb.ProhibitSendReceiveQuota.value){$mb.ProhibitSendReceiveQuota.value.ToMB()} else {“unlimited”}
$ProhibitSendQuota = if($mb.ProhibitSendQuota.value) {$mb.ProhibitSendQuota.value.ToMB()} else {“unlimited”}
$IssueWarningQuota = if($mb.IssueWarningQuota.value) {$mb.IssueWarningQuota.value.ToMB()} else {“unlimited”}
$userObj | Add-Member NoteProperty -Name “MBIssueWarning” -Value $IssueWarningQuota
$userObj | Add-Member NoteProperty -Name “MBProhibitSend” -Value $ProhibitSendQuota
$userObj | Add-Member NoteProperty -Name “MBProhibitSendReceive” -Value $ProhibitSendReceiveQuota
This could be helpful. Is it possible to have the script run against just “room mailboxes” ?
Tim,
Go to line 75, and add this line underneath:
[Parameter(ParameterSetName='room')] [switch]$room,
Go to line 139, and add this underneath:
if($room) { $mailboxes = @(Get-Mailbox $mailbox -RecipientTypeDetails RoomMailbox ) }
Save it and run it with the -room parameter. I tested this and it works.
Thanks BR – put doesnt the switch (-mailbox, -database -server, etc) specify where to pull the mailbox information from? Therefore using ‘-room’ switch it would have to be followed by the actual room ? I am trying to pull all rooms from a database or server.
Unless I am missing something. Thanks again !
The mailbox type us already included in the report, so you could just run it without modifications and use Excel to filter the data afterwards.
Another way would be to generate the list of room mailboxes into a text file and use the -file parameter when running the script.
Or, yet another way, make a copy of the script and call it say “Get-RoomMailboxReport.ps1″ and as BR suggests above change all the Get-Mailbox commands to add the “-RecipientTypeDetails RoomMailbox” parameter.
If you are getting the “No mailboxes were found matching that criteria.” message, make sure you are running the script in the Exchange Management Shell, this fixed it for me on Exchange 2007 and 2010.
Many thanks for this script, saved me many hours and lots of fingernails!
Hi Paul,
I have added one Ps1 file which is calling\having one function. I’m able to run the function( ex: get-Mail….). All is well.
Can you help me to know, how to remove the Ps1 file and the function Get-Mail… in my exchange server environment. I don’t want others to run this shell command, whenever i need the details, i ll run the script and get the data.
Help me to remove the function and PS1 file in safe manner
I don’t understand your question.
I followed this article to use get-databasestatistics function. I’m able to use this EMS shell command.
http://www.mikepfeiffer.net/2010/03/exchange-2010-database-statistics-with-powershell/
I want to remove the new Get-Databasestatistics command from my exchange environment. If I remove the ps1 file from the scripts folder, will this shell command get removed? or do i need to un register the script in someway…? Kindly advice
Thank you
Yes, if you delete a script file you won’t be able to run that script any more.
Why on earth would you want to remove that cmdlet? You know you can restrict who can run what cmdlet, right?
Kickass script Paul! Thanks for sharing.
Awesome script. Can you add functionality to show whether Exchange Archiving is enabled and the Total Size and Total Items in the archive? So far it seems the best way to check if archiving is enabled is to use Get-Mailbox | Select-Object ArchiveDatabase. Someone please correct me if I am wrong though. A value of null means archiving is disabled. I added some lines to the script and this worked.
When I tried to use Get-MailboxStatistics -Archive | Select-Object TotalItemSize,ItemCount this seems to work, but if the mailbox doesn’t have archiving enabled it throws out an error. I’m new to powershell scripting so I don’t know the best way to add this to the script so it’s handled gracefully.
Thanks!
I do not normally post comments on any website, but I just felt I had to this time!
Thank you – you have made my job about a milliontimes easier with this script…and such a simple thing it is too when you delve into it.
Why I had not thought of doing this sort of thing myself before I will never guess…but today, yes today Paul, you have made a new friend for life!
Once again, thank you mate!
I am not familiar with Exchange. When I run the script I get these error:
Can you help me find the missing links?
PS C:\Mailboxes> .\Get-MailboxReport.ps1 -database ‘PWRExchange\PWRE_MBX_2-2′
Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern ‘Microsoft.E
xchange.Management.PowerShell.Admin’ were found. Check the pattern and then try
the command again.
At C:\Mailboxes\Get-MailboxReport.ps1:89 char:27
+ $2007snapin = Get-PSSnapin <<<< -Name Microsoft.Exchange.Management.PowerShe
ll.Admin
+ CategoryInfo : InvalidArgument: (Microsoft.Excha…owerShell.Ad
min:String) [Get-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.G
etPSSnapinCommand
Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern 'Microsoft.E
xchange.Management.PowerShell.E2010' were found. Check the pattern and then try
the command again.
At C:\Mailboxes\Get-MailboxReport.ps1:96 char:28
+ $2010snapin = Get-PSSnapin <<<< -Name Microsoft.Exchange.Management.Powe
rShell.E2010
+ CategoryInfo : InvalidArgument: (Microsoft.Excha…owerShell.E2
010:String) [Get-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.G
etPSSnapinCommand
Import-Module : The specified module 'ActiveDirectory' was not loaded because n
o valid module file was found in any module directory.
At C:\Mailboxes\Get-MailboxReport.ps1:124 char:14
+ Import-Module <<<< ActiveDirectory
+ CategoryInfo : ResourceUnavailable: (ActiveDirectory:String) [I
Please Help!
@Kalvin – it looks like you are running that script from within a regular PowerShell console. You either need to load the Exchange snap-ins into that console, or instead run the Exchange Management Shell version of the PowerShell console (preferably IMHO). The Exchange Management Shell is installed on any computer you install the Exchange Administration tools on.
Happy hunting!
I am actually running it remotely and I am not in Exchange admin group. I have been given readonly access. Does that suffice or I need to do more?
Thanks!
Kalvin, as HotFix says, you will only be able to run this script either from with in the Exchange Management Shell version of the PowerShell console on an exchange server or from a computer that has the Exchange Administration tools installed onto it.
You can use the following command to load the Exchange Management tools in a script though, if that helps or you have problems fiding the Exchange console.
function Load_Exchange_Tools {
if (-not (Get-pssnapin | ? {$_.name -like ‘Microsoft.Exchange.Management.PowerShell.e2010′})) {
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.e2010
}
}
If you don’t have access to the tools, or your permissions don’t allow access to Exchange, you won’t be able to run scripts like this though.
Rgds, Shane.
This is brilliant, thanks
e.s. I changed the export command to $report | Export-Csv -encoding ‘unicode’ -Path $reportfile -NoTypeInformation – because here in Iceland we have alot of strange Icelandic characters like æ á þ ð ó and so on!
Nice work.
best regards, Bjarni
Excellent.
It seems that code
#This is an aged mailbox, so we want some extra details about the account
$user = Get-User $mb
isn’t exact
better is
$user = Get-User $mb.Alias
Seems to be working okay for me (although that comment about aged mailboxes doesn’t seem right, must have slipped in from another script).
Have you ever considered using a txt or csv file as input? I am currently evaluating Petri’s script for the same and can’t specify an input file. After analyzing your script, I find my problem as it is. Can you suggest me a way where I can specify a TXT or CSV file as input for users?
Thanks,
Animesh
The script has a -file parameter for using a txt file as the list of users to generate the report for. The txt file should contain the list of mailbox users in a format that would work with Get-Mailbox, so that could be alias, email address, display name, etc.
Hi thank u a lot for your wonderfull script.
I need to bublic it to may intranet site. How convert it in html formatted tablereport?
Could u modify the script to add html export?
I’m trying to modify it but I’m not able.
Thank you very much.
David.
David, do you have SQL reporting services available to you?
We take the data from this script and it gets imported into a database for SQL reporting. It allows me to see weekly growth on mailboxes by department and user. I totally recommend that if you have the resources available to you. Perhaps that might be more useful than simply dumping it into a html file, using a database and reporting services will let you track growth, find the heaviest mail users – and if your company is so inclined, charge accordingly.
Before I found this script we were going to spend a great deal of money on a reporting system that went through the Exchange server logs. This script coupled with SQL reporting has pretty negated that.
Anyhoo, there IS a ConvertTO-HTML option you can use with PowerShell, this link may help.
http://technet.microsoft.com/en-us/library/ff730936.aspx
Hi Shane,
how is this done ? I am quite interested in doing this. Could you or any one else shed some more light on it ?
thanx.
Hi Ray. I use the script that Paul kindly created with just a couple of slight modifications. My copy of it is here; http://pastebin.com/yVyJdpxh
One change was the folder where it dumps the csv file. The other change was appending the date to the filename of the csv file to create a history. I take no credit for this, from memory Paul helped me work that out also
There is a scheduled task on our Exchange server that runs this script once a week. Another scheduled task then robocopies the csv file to a SQL server that’s running Reporting Services. We then convert the .csv file to a .xls file, cleaning some of the data up. This excel file is then fed into the reporting database and then displays in the report when that is run. I’d past an export of that, but there’s corporate information in it so here’s a snippet of it, with corporate info blurred out.
http://img827.imageshack.us/img827/387/captureqzh.jpg
The report can be filtered by date, department etc so the majority of the work here was in the quality of the report created by our apps\dev person.
It also drops down to show the users from each department and the size of their mailbox on those dates. It’s shows growth, but also shows when someones doing a mass delete in their mailbox (perhaps a pending resignation etc, so we make a note of this in case we have to restore it from tape at some point).
So unfortunately my ability to help further is hindered by the fact that the majority of the awesomeness was done by our awesome report writer. They take the data dump from this file and turn it into something useful
Thanx a lot Shane.
Hi Shane,
Can you please provide the code to import excel file to SQL reporting DB server
Hi CRAZY IT guy. It’s a standard INSERT
First we edit the spreadsheet a bit by changing the date from 020712 to 02/07/2012 which is done manually, then our code to import it is;
INSERT INTO [ExchangeReporting].[dbo].[MailboxReport]
select *
from [ExchangeReporting].[dbo].[MailboxReport-070512]
Obviously things will change for your environment such as the database name etc, also the file name is changed for each import as well. I hope that helps.
Hi Bryan, thank you for your answer.
I do not have a sql database but only a intranet webs erver where to publish the html report.
I saw the codee like this:
$style = “BODY{font-family: Arial; font-size: 10pt;}”
$style = $style + “TABLE{border: 1px solid black; border-collapse: collapse;}”
$style = $style + “TH{border: 1px solid black; background: #dddddd; padding: 5px; }”
$style = $style + “TD{border: 1px solid black; padding: 5px; }”
$style = $style + “”
$message.Body = Get-ExchangeServer | Select-Object Name,ServerRole | ConvertTo-Html -Head $style
Where can i put this code in your script to have the csv to html report file?
I tried to insert in the following part of your script code but but I did not get the html table file:
$reportcount = $report.count
if ($reportcount -eq 0)
{
Write-Host -ForegroundColor Yellow “No mailboxes were found matching that criteria.”
}
else
{
#Output single mailbox report to console, otherwise output to CSV file
if ($mailbox)
{
$report | Format-List
}
else
{
$report | Export-Csv -Path $reportfile -NoTypeInformation ???–> in this part?
Write-Host -ForegroundColor White “Report written to $reportfile in current path.”
Get-Item $reportfile ?? or in this part?
}
}
Thank you so much for you help.
David.
Thank you, this script has been very helpful! I do have one question that on an issue I see when I use it.
Each time I run it I see a number of errors saying the following. Please note the
The operation could’nt be performed because object ” couldn’t be found on ”.
+ CategoryInfo :NotSpecified: (:) [Get-User], ManagementObjectNotFoundException
+FullyQualifiedErrorID: : ,Microsoft.Exchange.Management.RecipentTasks.GetUser
This happens to users that are in one specific domain (which I can query with no issues in AD Management). Would anyone have any ideas on what I can do to resolve this?
Please disregard my previous post. I found the answer to my issue only moments later. I corrected the recipent scope and all is fine.
Thanks for your help by providing this Scrip, However I have tried to us is from ( Exchange powershell and Windows Poershell ) and while trying to import it there is an error message :
[PS] C:\Scripts>import-module .\Get-Mailboxreport.ps1
Collecting mailbox list
Collecting report data
No mailboxes were found matching that criteria.
Thanks
Hi Aziz, this is a script to run, not a module to import. Please review the article above again, read the built-in help for the script, or watch the video. They all demonstrate how to run the script.
OOOh, YES, I have tested and it is working perfectly ….
Really Thanks
Excellent script, thanks for sharing!
Works like a charm. One question though. How did you get excel to sort the csv file automatically?
Not entirely sure what you mean. Excel has a Sort button, I usually just use that. Is that what you meant?
Hi Paul,
I want to be run powershell command for Send As permissions in exchange 2010 ….which command should be used normally I am giving manually in exchange 2010 console..can you post Send as permissions command and if you possible share all the basic commands etc..add permissions.. DLG Creation .. and RMB Creations
Hi Paul. I notice in the script that the variable $timestamp is used in 2 places?
$timestamp = Get-Date -UFormat %dd%mm%yy
$reportfile = “C:\PSScripts\Copy\MailboxReport-$timestamp.csv”
this places the timestamp on the file name (which is invaluable)
and also;
$userObj | Add-Member NoteProperty -Name “Date” -Value $timestamp
places the time stamp into the spreadsheet data itself, next to the user name, dept, mailbox size etc.
in the csv file, the date is displayed as 060712 (when I run it today).
is it possible, to have the date (in the data, not necessarily the file name – as it won’t like slashes) be in the 06/07/2012 format?
that might require the creation of a second timestamp variable though just for the date inside the csv file?
if i change the $timestamp variable to;
$timestamp = Get-Date -UFormat %dd%mm%yy
the date on the file, and in the data gets written as; 06d07m12y
I don’t expect you to solve the worlds problems for us, but is there a link or something you can share that will educate me on how to achieve the date formatting I need?
Cheers, Shane.
Is this a modification you’ve made to the original?
$userObj | Add-Member NoteProperty -Name “Date” -Value $timestamp
Possibly :p It was a while back now. Apologies if I’ve turned your beautiful script into some bastard child :-p
Yeah I just don’t see it in the original. Modifications are fine, people should certainly feel free to tweak these scripts to suit their needs.
So what is the goal of that extra property you’re trying to set? Is it so your SQL import knows which day the stats apply to?
Hi Paul, yep at present I manually edit the csv file and replace all the 020712 date data with 02/07/2012 manually.
it doesn’t take long, but the more i can automate the better
Try this:
$a = Get-Date -f d
$userObj | Add-Member NoteProperty -Name “Date” -Value $a
You can use any variable name you want I’m just $a for the sake of example.
Thank you Paul, that did the trick.
I now have 2 variables.
$filetimestamp = Get-Date -UFormat %d%m%y
$datatimestamp = Get-Date -f d
$filetimestamp is appended to the csv file when it’s written.
$datatimestamp is used in [$userObj | Add-Member NoteProperty -Name "Date" -Value $datatimestamp] and displays the date as “6/07/2012″ inside the csv file
Perfect! Thank you so much
Awesome, good stuff.
Thanks again, I didn’t know about Get-Date -f d, so cheers for that
Hi Paul,
Great Stuff, is it possible to alter the script to display total mailbox size per user, currently it only displays, Item Size and deleted item size.
Regards,
Brian
The script is awesome Sir and so are you of having written it!
Hi Paul,
I ran your script, it worked fine, thank you. I summed the Mailbox and deleted items they added up to 112Gb, but my two edb files are 86Gb and 45Gb, any idea wat is using the extra 20Gb? Db maintenace runs nightly.
Hi Peter,
A few articles that may help you determine what is using the extra space.
http://exchangeserverpro.com/defrag-exchange-2010-mailbox-database
http://exchangeserverpro.com/defrag-exchange-server-mailbox-databases
http://exchangeserverpro.com/exchange-2010-mailbox-database-growing-big-fast
The AvailableNewMailboxSpace is the usual culprit though. Running this command will show you that stat for your databases:
Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto
Hi Paul,
Thanks Exactly what i was looking for, Is it possible for you to add the option to email the report.
10x.
Can i run ..powershell command as the following requirements.
1 ) DLG Creation
2 ) RMB Creation
3 ) moving mail box from one location to another location ( Database )
4 ) how to view log if we applied succesfully p-shell commands
Paul when i run the script I get:
WARNING: Error initializing default drive: ‘Unable to find a default server with Active Directory Web Services
running.’.
but then it looks like it runs…
anyideas..
thanks
If you don’t have any 2008 R2 domain controllers you’ll need to install the AD Web Service for Server 2003/2008 here:
http://www.microsoft.com/en-us/download/details.aspx?id=2852
Hi Paul,
How can i get output of EmployeeType and EmailAddresses in this script.
Thanks
Vivek
The script is not digitally signed. Can you get it signed. Here are the steps
http://blogs.technet.com/b/heyscriptingguy/archive/2010/06/17/hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-2-of-2.aspx
very nice Script, Works perfectly for me with limited count.
I have 500 mailbox, but i am getting only 139.
.\Get-MailboxReport.ps1 -server Exmbx02 -filename e:\allmailbox.csv
Please advise to get the full mailbox report.
Thanks
Alagar
By executing the following command it is giving the full report,
.\Get-MailboxReport.ps1 -full -filename e:\allmailbox.csv
Thanks
Alagar
Nice script. But i have a question, could you advise on how i can generate a report that will include the “date” a mailbox is disbled. In otherwords, the disabled date for all disabled mailboxes.
Thank in anticipation.
Do you already know how to retrieve the disabled date for a mailbox, and just want to know how to incorporate that into the script? Or are you also asking how/if its possible to retrieve the disabled date itself?
I am in Norway and the DisplayName contains ØÆÅ characters that are not in the generated reports, there they are substituted by a questionmark.
Do you have a fix for that?
Hi Peter, someone else encountered the same problem and fixed it by adding the -encoding switch to the Export-CSV command towards the end of the script
Eg,
Export-Csv -encoding ‘unicode’
Just wanted to drop a note of thanks for this script. I’ve been cobbling together a couple different reports to get me (and my supervisors) what we need. That was excellent. Cheers!
Dont suppose you could give us a ZIP file of this script. We dont allow direct internet downloads of PS1 extentions.
It already is provided as a Zip file.
how can you sort the office, department and Total item size in the script?
I have an issue with the saved report.
The first characters of the file are not “normal” characters.
When using the report in Linux the file is being identified as a assembler file, not a text file.
How can i fix this in the report generated instead of writing a workaround in my scripting language on the linux machine?
Cheers, Peter
Maybe try playing around with the -Encoding options for Export-CSV
Excellent One.
how to get mailbox details which includes the Servername, databasename, username – ,maybe display name etc.
I gave the command as follow.
get-mailbox -database dbname -server servername. But getting ambigous error. Can you please help me out in this.
Use -database or -server, but not both at the same time.
Paul,
Thanks for the great script. I modified the Total Item Size and Deleted Item Size ToGB() because of the size of the mailboxes I am dealing with. I was wondering how I could format the values to 2 decimal place ex 9.65 right now it is displayed as 9. I tried figuring this out on my own but I am a powershell noob.
Thank you
This article on number formatting should help:
http://technet.microsoft.com/en-us/library/ee692795.aspx
the formatting works perfect when you run a single command as instructed on the linked site, but I have not been able to incorporate it in the script … yet
Is it possible to get this script to report on mailboxe sizes based on the Office the person(s) are located in?
Anything is possible with PowerShell mate
I would encourage you to look at the script code. Look at how the parameters are defined. Look at how those parameters correspond with the Get-Mailbox commands. You should be able to quickly see how to add that functionality you want.
Hei Paul,
Is there a way to suppress the first row?
Aka, only having in data in the file and not the property name on the first line.
Thanks,
No, can’t see a way to do that with Export-CSV
Paul
Many thanks, your video was greatly helpful in understanding teh script’s functionality
Paul,
I’m trying to run the script, however my databases have users from 3 seperate child domains. The report runs through for the local domain where the Exchange servers are hosted, but throws errors about not being found on the Domain Controller. I have a similar issue when I have to do exports and actually define the DC for the other child domain to pull an export. Any way this can be addressed in the script?
At about line 130 in the script is the series of Get-Mailbox commands for the various all/server/database scenarios. You can modify those lines to specify a DC if you need to.
Interesting that you’re having that problem at all. The script is designed to ignore default scope and search the entire forest, so it should find any mailbox regardless of child domains.
Paul,
Once it ran against the whole Server, it DID pull me back the info for the mailbox size and item count, but it didn’t pull back the AD info for the mailbox except mailbox user name. At the end, it did what I really needed, so THANK YOU!
The script is perfect the only thing that would make it even better for me is to include the following: IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota. Any chance you could do it?
Hey Paul. Great script outside of a couple minor suggestions.
If the script requires a specific version of PowerShell; include the following:
#requires -version 2
write-host “Can only run on v2.”
Also, it may be a better choice to use, “Set-ExecutionPolicy RemoteSigned” instead of “Set-ExecutionPolicy Unrestricted”
Cheers
Great Script, i love it…..
I am new in Powershell World.
But how can change the Field Separator from “,” to “;”.
Change the Export-CSV line in the script to include the -Delimiter parameter.
More info here:
http://mcpmag.com/articles/2011/03/export-csv-cmdlet-delimiter-parameter.aspx
Thanks, it works perfectly…
Hi Paul!
Thanx for sharing a script. One question. Is there a solution to add another value for get-mailbox with prohibitsendquota option. It would be usefull to get that info with all this usefull info.
Thanx.
This is really handy. Thanks!
To setup a monthly mailbox report just create a cmd batch file with the following command line in it, then set it as a task on the exchange server to run each month:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command “. ‘C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1′; Connect-ExchangeServer -auto | “C:\scripts\Get-MailboxReportMin.ps1 -all
All the Beast Matt
Thank you much and great work as always. Anyone know a way to add the Sent Items to the report? TotalSentItemSize to the Select-Object line and $userObj | Add-Member NoteProperty -Name “Sent Item Size (Mb)” -Value $stats.TotalSentItemSize.Value.ToMB() to the PS object. The script runs fine but does not output the Sent Items value.
Thanks,
Ken
I have customers who have multiple databases for their mailbox. Is there a way to alter the -database paremeter to analyze all databases that begin with a specific set of characters?
I think I’ve found a way to resolve my issue. I added these lines in the appropriate places in the script:
[Parameter(ParameterSetName='CustomAttribute1')] [String]$CustomAttribute1,
if($CustomAttribute1){ $mailboxes = @(Get-Mailbox -Resultsize Unlimited | where {$_.CustomAttribute1 -eq $CustomAttribute1} ) }
This allows me to report on a subset of my users regardless of what database their mailbox is in. It does take a while to gather the matching users before processing but if I schedule this and other variations to run at night it should not put a crunch on the server. I already run nightly scripts to set the proper value for CustomAttribute1 for users.
This is a really nice script that is well documented and I truly appreciate it.
Hey,
Great script. I am trying to figure out how to get one more field added, all SMTP addresses (aliases) for all users. How can I accomplish this.
I typically do the following:Get-Mailbox | Select DisplayName, Alias,PrimarySMTPAddress, @{Name=’EmailAddresses’;Expression={[string]::join(“;”, ($_.EmailAddresses))}}
I am not sure how to integrate that here.
Thanks for the help!
At about line 185 add these lines:
$emailaddresses = [string]::Join(“;”,($mb.EmailAddresses))
$userObj | Add-Member NoteProperty -Name “SMTP Addresses” -Value $emailaddresses
Paul,
Love the script…Is it possible to add Online Archive MB as a column? I’d like to determine the size of each Archive MB as well.
Thanks
It is something I want to add in the next version, when I have time to do a few updates to it.
Getting her late to the party but a very awesome script! Great dialog in the thread as well for situation-specific needs!
Thanks!
Great information on all your posts.
I’m getting this error:
WARNING: Error initializing default drive: ‘Unable to find a default server with Active Directory Web Services running.’.
You need a DC running Windows Server 2008 R2, or one running the AD web service:
http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=2852
Hi Paul,
I have modified your script to give information on online Archive if one is enabled. Insert my code in $userobj section:
…
$userObj | Add-Member NoteProperty -Name “Database” -Value $mb.Database
#========Online Archive code================
if ($mb.ArchiveDatabase)
{
$astats=$mb | Get-MailboxStatistics -Archive
$userObj | Add-Member NoteProperty -Name “Archive Item Size (Mb)” -Value $astats.TotalItemSize.Value.ToMB()
$userObj | Add-Member NoteProperty -Name “Archive Deleted Item Size (Mb)” -Value $astats.TotalDeletedItemSize.Value.ToMB()
$userObj | Add-Member NoteProperty -Name “Archive Items” -Value $astats.ItemCount
$userObj | Add-Member NoteProperty -Name “Archive Server” -Value $astats.ServerName
$userObj | Add-Member NoteProperty -Name “Archive Database” -Value $astats.Database
} else {
$userObj | Add-Member NoteProperty -Name “Archive Item Size (Mb)” -Value “”
$userObj | Add-Member NoteProperty -Name “Archive Deleted Item Size (Mb)” -Value “”
$userObj | Add-Member NoteProperty -Name “Archive Items” -Value “”
$userObj | Add-Member NoteProperty -Name “Archive Server” -Value “”
$userObj | Add-Member NoteProperty -Name “Archive Database” -Value “”
}
#=====Online Archive code ends==================
Also to support non-latin characters in your report and to be able to open straight with MS Excel change your export command to
#========New export code=================
$report | Export-Csv -Path $reportfile -NoTypeInformation -delimiter “;” -encoding “utf8″
#========New export code end=================
Had some trouble getting this to work. When you typed Get-M it autocompleted the rest for you, It did not do this for me, I tried typing out the whole command but kept getting an error that it could not find the script. I had to type out
.\Get-MailboxReport.ps1
with the .\ in front before it would run. spent about 10mins before I figured that out…… Sure was much easier when you could open exchange 2003 and it told you how big the mailboxes where in a GUI.
Good article though, thanks for the help.
Hi Paul,
Great script and have been using it for a couple years.
Over the past couple days I have been getting the following error;
Parameter cannot be resolved using the specified named parameters. At line:1 char:24
Any ideas?
Thanks!
Have you modified the script or upgraded your version of PowerShell or something like that?
Note also that some combinations of parameters can’t be used. Eg, you can’t use -Server and -Database together.
thanks for the quick reply.
it ended up being UAC settings set too high.
thanks!
I’m getting this same error now as well.
No updates on the mail server. No PowerShell upgrades but when I try and run it, I get;
[PS] C:\psscripts>.\Get-MailboxReport.ps1
C:\psscripts\Get-MailboxReport.ps1 : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:24
+ .\Get-MailboxReport.ps1 <<<<
+ CategoryInfo : InvalidArgument: (:) [Get-MailboxReport.ps1], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Get-MailboxReport.ps1
You need to specify at least one parameter, -all, -server, -database, etc.
How can i get the first name & email address of the users in the csv file?
This script is great, a real time saver. I do have one question. We have 2 MB servers that are in a DAG. When I run against one I only get about 1/4 of the mailboxes returned. I know they’re all on both as we flip back and forth on mount points when we need to to perform maintenance (and the DB sizes are the same on both). Any idea why only one would return full results and the other incomplete?
Thanks!
The -Server parameter for the script isn’t really suited to DAGs. That is probably because when I first wrote it there were no DAGs in the environment I was working in.
The ServerName on a mailbox that is hosted on a DAG is misleading. I believe it gets stamped with the server name that the database was active on at the time the mailbox was created, but doesn’t update as active databases switchover.
thanks Paul. what happened is i have a few scripts set to run automatically via task scheduler, i inadvertently deleted the task that run this one – which had all the parameters so it would run as intended.
i was trying to run it manually, without those – sorry about that
Cheers Shane.
Hi Paul.
First off, GREAT script!
Is there a way to break down the stats by date range per mailbox? Example:
Items 0-15 days, Size 0-15 days, Items 16-30 days, Size 16-30 days, etc.?
I guess you could use EWS to analyse the mailbox contents but I imagine it would slow down the script enormously.
Can the script be modified to include the active directory distinguished name (ID and container) ?
Sure. I would certainly encourage you to look at the code and modify the script to suit your own needs.
I LOVE THIS SCRIPT! I’ve been using it for a while and it helps me to identify “dead” mailboxes, their sizes, etc. However, I recently ran into an issue that I am unable to figure out.
If I run the script against my lab environment (or most any other for that matter) with Exchange 2010 SP3, I receive information for all of the headers…
“DisplayName”,”Title”,”Department”,”Office”,”Enabled”,”Expires”,”Last Mailbox Logon”,”Last Logon By”,”Item Size (KB)”,”Deleted Item Size (KB)”,”Items”,”Type”,”Server”,”Database”
But, I ran into a situation where two of the headers do not show in the report. And these headers (and info) are quite important to determine our migration strategy. The two headers that do not show are…
“Item Size (KB)”,”Deleted Item Size (KB)”
I am running the same command and the same switches (using server name) but the results are different in this particular environment.
Paul, any ideas why this might be occurring?
Todd
I’ve been successful a few months back in manually running your excellent script but tried again today and nothing happens. No errors but no CSV files appear. Command line looks like this:
PS C:\scripts>”.\get-mailboxreport -all” or “.\get-mailboxreport” are accepted without any feedback.
I am running this on the active mailbox server against a DAG in Exchange 2010. I must be missing something really simple! Advice?
Allen,
Does the account you are running the script with a member of the “Organization Management” group? I don’t feel the account needs Enterprise Admins membership but may since the script seems to query AD.
Todd
My account is a domain admin and a member of the Exchange Organization Administrators. I can try adding myself to the Organization Management group to see if that makes any difference. Will update in a few. Thank you.
Todd,
No difference. Here is an example of what I see in the EMS – the command seems to simply echo back but no CSV files or even errors or additional info is generated:
PS C:\scripts> “.\get-mailboxdatabase -all”
.\get-mailboxdatabase -all
PS C:\scripts>
Typo – please excuse me. Here is the actual text from the screen ….
PS C:\scripts> “.\get-mailboxreport -all”
.\get-mailboxreport -all
PS C:\scripts>
Allen
One thing that I see is very curious. The name of the script referred to in this thread is “Get-MailboxReport.ps1″. Therefore, the command being run should be “.\get-mailboxreport -all”. So, I feel this is probably a typo.
If it is still not running for you, I cannot think of anything else but to make certain the file is unblocked from running and that the report output is being sent to a folder that isn’t set to read-only.
I am running Exchange 2010 SP3 hosted on WS2008R2SP1 with PowerShell 2.0.
When I run the command, this is what I see…
[PS] C:\Tools\Get-MailboxReport>.\Get-MailboxReport -all
WARNING: Active Directory server settings remained unchanged.
Collecting mailbox list
Collecting report data
WARNING: The user hasn’t logged on to mailbox ‘red.local/Users/DiscoverySearchMailbox {D919BA05-46A6-415f-80AD-7E09334BB852}’
(’5631bcc1-7f67-4600-9fcb-82e652b92d2f’), so there is no data to return. After the user logs on, this warning will no longer appear.
Report written to MailboxReport-20130509-1346-1rFbV8.csv in current path.
Directory: C:\Tools\Get-MailboxReport
Mode LastWriteTime Length Name
—- ————- —— —-
-a— 5/9/2013 1:46 PM 2594 MailboxReport-20130509-1346-1rFbV8.csv
[PS] C:\Tools\Get-MailboxReport>
Another thing I could recommend is to download the script again but to a new/different folder on your mailbox server and try to run again.
Todd,
Thank you very much for all of your replies. Yes, there was a typo that you picked up. I’ve tried running:
PS C:\> cd scripts
PS C:\scripts> .\get-mailboxreport -all
Collecting mailbox list
Collecting report data
No mailboxes were found matching that criteria.
And tried running:
PS C:\scripts> “.\get-mailboxreport -all”
.\get-mailboxreport -all
And you see the results. Tried another download to another directory with the same results. Permissions are all fine. I am running Exchange 2010 SP1 rollup 8 on Windows Server 2008 R2 Datacenter with SP1 and powershell V1.
Here’s what I see after a fresh download to the C:\Tools directory (newly created directory with permissions rechecked):
PS C:\tools> get-executionpolicy
Unrestricted
PS C:\tools> .\get-mailboxreport -all
Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
computer. Do you want to run C:\tools\Get-MailboxReport.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”): R
Collecting mailbox list
Collecting report data
No mailboxes were found matching that criteria.
Interesting. Different info on the screen this time though.
Database names in the DAG are DAGDB1 and DAGDB2. Calling them in the -database variable doesn’t change anything either.
You need to run it in the Exchange Management Shell or at least a PowerShell window where you’ve loaded the Exchange snapin.
If you just open plain PowerShell and run it then you get no results, as you’re seeing.
The next version of the script will account for that and give a more useful error if the snapin can’t be loaded.
Paul, that was exactly the problem I was having. I was opening the Exchange Management Shell and then typing powershell to bring up the PS> prompt that I was seeing in the video. Running it strictly from the EMS works perfectly.
Todd and Paul, thanks again for all your help. Great stuff and great script!
Thanks for this script Paul. It works very well, and is a great foundation for learning more PS Exchange scripting techniques.