Exchange 2010 how to view a users folders sizes in Powershell

If you have a user who is receiving the following message:
“The recipient’s mailbox is full and can’t accept messages now. Microsoft Exchange will not try to redeliver this message for you. Please try resending this message later, or contact the recipient directly.”
They might be asking you what is taking up so much space.  There is a simply Powershell command you can run that will generate what folders are consuming the space.
Get-MailboxFolderStatistics -id | sort-object foldersize -descending | FT folderpath, foldersize, itemsinfolder -autosize
This will return something like this which you can give to the end user.
FolderPath                            FolderSize                    ItemsInFolder
———- ———- ————-
/Sent Items/Inbox                     1.793 GB (1,925,310,217 bytes)         16941
/Deletions                           1.046 GB (1,123,250,629 bytes)         10579
/Inbox                               865.8 MB (907,805,987 bytes)            7326
/Sent Items                          240.6 MB (252,339,324 bytes)            3194
/Sent Items/Deleted Items             45.5 MB (47,705,521 bytes)              672
/Recoverable Items                   8.272 MB (8,674,112 bytes)             2208
/Calendar                             5.487 MB (5,753,889 bytes)              1095
/Top of Information Store             3.216 MB (3,372,347 bytes)               38
/Drafts                              1000 KB (1,024,409 bytes)                18
/Contacts                             8.507 KB (8,711 bytes)                   20
/Deleted Items                        323 B (323 bytes)                         1
/Junk E-mail                          138 B (138 bytes)                          1
/Purges                               0 B (0 bytes)                             0
/Versions                             0 B (0 bytes)                              0
/Tasks                               0 B (0 bytes)                             0
/Journal                             0 B (0 bytes)                             0
/Conversation Action Settings         0 B (0 bytes)                             0
/Outbox                               0 B (0 bytes)                              0
/Notes                                0 B (0 bytes)                             0

Get the ten biggest mailboxes in Exchange 2010 export to report using PowerShell

Get-Mailbox -database  | Get-MailboxStatistics | Sort-Object TotalItemSize -descending |Select-Object DisplayName,ItemCount,@{name=”MailboxSize”;exp={$_.totalitemsize}} -first 10 | Convertto-Html | out-File report.htm

Use Powershell in Exchange 2010 to give a distribution group permissions to a security group's member's calendars'

The first thing you will want to do is create and active directory security group.  In my example I create one named “calendartest”.  Now I’m going to add all the users who need to have their calendar shared with a distribution group of users to this group that I’ve created. 
Now open adsiedit.msc so you can find the location of the group in active directory.  You are going to need this.  In my example it is “CN=calendartest,OU=MyUsers,DC=TestDomain,DC=local”.
Finally open powershell and simply run these two commands:
$calendartest = Get-mailbox –Filter {(MemberOfGroup -eq “CN=calendartest,OU=MyUsers,DC=TestDomain,DC=local”)}
$calendartest | ForEach-Object {Add-MailboxFolderPermission $_”:Calendar” –User –AccessRights Reviewer}

Manage Exchange 2010 Calendar Permissions Using Powershell

In this example we will add a domain group named group-calendarReviewers to a mailbox named Jeremy.Whittaker.  We will give the group “Reviewer” access rights
Add-MailboxFolderPermission -identity “Jeremy.Whittaker:calendar” –user “DomainNamegroup-calendarReviewers” -AccessRights Reviewer
In this example above I use reviewer.  However, instead of using “Reviewer” permissions you may choose from all these different types of permissions:
None                                                   FolderVisible
Owner                                                CreateItems, ReadItems, CreateSubfolders, FolderOwner, FolderContact, FolderVisible, EditOwnedItems, EditAllItems, DeleteOwnedItems, DeleteAllItems
PublishingEditor                       CreateItems, ReadItems, CreateSubfolders, FolderVisible, EditOwnedItems, EditAllItems, DeleteOwnedItems, DeleteAllItems
Editor                                                 CreateItems, ReadItems, FolderVisible, EditOwnedItems, EditAllItems, DeleteOwnedItems, DeleteAllItems
PublishingAuthor                    CreateItems, ReadItems, CreateSubfolders, FolderVisible, EditOwnedItems, DeleteOwnedItems
Author                                              CreateItems, ReadItems, FolderVisible, EditOwnedItems, DeleteOwnedItems
NonEditingAuthor                   CreateItems, ReadItems, FolderVisible
Reviewer                                          ReadItems, FolderVisible
Contributor                                   CreateItems, FolderVisible
The following roles apply specifically to calendar folders:
AvailabilityOnly                        View only availability data
LimitedDetails                            View availability data with subject and location
Now lets say you want to go through all the users in your domain and give the group group-calendarReviewers permissions to everyones calendar:
{codecitation}$users = Get-mailbox
$users | ForEach-Object {
Set-MailboxFolderPermission $_”:Calendar” -User Default -AccessRights AvailabilityOnly
Remove-MailboxFolderPermission $_”:Calendar” -User “DomainNamegroup-calendarReviewers” -Confirm:$False
Add-MailboxFolderPermission $_”:Calendar” -User “DomainNamegroup-calendarReviewers” -AccessRights Reviewer
}$users = Get-mailbox $users | ForEach-Object {{codecitation}

Redirect port 80 on exchange 2010 to ssl or 443 for OWA or Outlook Web Access

You must use caution when changing the IIS settings for Exchange 2010.  The reason is simple.  Powershell or the Exchange management console EMC uses IIS to manage Exchange.  So if you incorrectly change settings you will render your Exchange EMC and Powershell useless.

VERBOSE: Connecting to
[] The WinRM service cannot process the request because the request needs to be sent to a different machine. Use the redirect information to send the request to a new machine.  Redirect location reported: To automatically connect to the redirected URI, verify “MaximumConnectionRedirectionCount” property of session preference variable “PSSessionOption” and use “AllowRedirection” parameter on the cmdlet.
    + CategoryInfo          : OpenError: (System.Manageme….RemoteRunspace:RemoteRunspace) [], PSRemotingTransportRedirectException
    + FullyQualifiedErrorId : PSSessionOpenFailed
First thing you’ll want to do is go to your default website and change the redirect.  Use the settings from this image below.  Use them exactly, you have been warned.

Once that is complete you have to uncheck redirect on all of these sub directories.

  • aspnet_client
  • Autodiscover
  • ecp
  • EWS
  • Microsoft-Server-ActiveSync
  • OAB
  • PowerShell
  • Rpc

Exchange, Exchweb, and Public virtual directories should redirect to /owa.
Now if you try to open Internet Explorer you will receive a HTTP 403.4 error.  That is because SSL is required.  Select the default website just like the image below and remove the SSL requirement.

Once again you will have to go through these virtual sub directories and make sure the SSL box IS checked!

  • Autodiscover
  • ecp
  • EWS
  • Microsoft-Server-ActiveSync
  • OAB
  • owa
  • Rpc

Warning: If you require SSL for the PowerShell virtual directory, you will render Remote PowerShell inoperable!

How to limit users access to OWA in Exchange 2007 via powershell

The first thing you’re going to want to do is create two users in active directory. 
OWAEnabled and OWADisabled
You then need to mail enabled these two groups.
enable-DistributionGroup -Identity ‘domain.internal/OU/OWAEnabled’ -Alias ‘OWAEnabled’
enable-DistributionGroup -Identity ‘domain.internal/OU/OWADisabled’ -Alias ‘OWADisabled’
I would also hide them from the address list
 Set-Distributiongroup ‘OWAEnabled’ -HiddenFromAddressListsEnabled $true
Set-Distributiongroup ‘OWADisabled’ -HiddenFromAddressListsEnabled $true
From there add the users to their respective groups based on if you want their owa enabled or not.
Finally once you have that all setup run the following powershell commands
Get-DistributionGroupMember “OWADisabled” | Set-CasMailbox -OWAEnabled $False
Get-DistributionGroupMember “OWAEnabled” | Set-CasMailbox -OWAEnabled $True

Send a daily html CCR report via Powershell

Create a powershell script to generate the html file

Test-ReplicationHealth | ConvertTo-Html -title “BackupReport CCR” -body “Backup status per Storage Group” | Set-Content E:StorageGroupBackupStatus.html



Create a powershell script to e-mail log file

$filename = “E:StorageGroupBackupStatus.html”
$smtpServer = “RelayServer”
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “
$msg.Subject = “CCR Status”
$msg.Body = “Attached is the CCR status”

Go into task scheduler

For the program type this
For the arguments use
-PSConsoleFile “C:Program FilesMicrosoftExchange Serverbinexshell.psc1” -noexit -command “. ‘e:SendLogFile.ps1′”

Creating a recovery storage group and database

Creat a new storage group

New-StorageGroup –Server <database server> –LogFolderPath “<Path to your log folder” –Name “Recovery Storage Group” –SystemFolderPath “<path to your database>” –Recovery

Creat a new database

New-MailboxDatabase –MailboxDatabaseToRecover “<database>” –StorageGroup “<database server><storage group name>” –EDBFilePath “<path to the database file>”

 Allow file restore

Set-MailboxDatabase -Identity “ServerNameRecovery Storage GroupDatabase” -AllowFileRestore
Mount-Database –Identity “<server>Recovery Storage Group<database>”

Exchange 2007 Powershell to copy contacts from storage recovery group to production database

Get-MailboxStatistics -Database “<DBServer><Recovery Storage Group><Database>” | Restore-Mailbox
-RSGDatabase “<DBServer><Recovery Storage Group><database>” -IncludeFolders Contacts –

Sending an email with Powershell

$SmtpServer = “yourServer”
$From =
if ($args.Length -lt 1) {
     $To =
else {
     $to = $args[0]
$subject = “Need computer consulting”
$Body = “Hi, this is John Doe I need cheap Exchange consulting at $125/hour”
$smtpClient = new-object
$ = $smtpServer
$smtpclient.send($from, $to, $subject, $body)
Once this file is saved to ps1 format you can use it via this syntax