Powershell Needful Things put that in your pipeline


Exchange 2010 stale & unused mailbox cleanup tool

Posted by Jean Louw

I have finally completed the testing of the User Mailbox Cleanup tool for Exchange 2010.

Although this script is run from the EMS, it opens as a GUI utility which Exchange Administrators can use to cleanup stale or old Exchange mailboxes from Exchange 2010 mailbox servers.
The utility has a couple of preset search queries to help locate stale or old mailboxes, and once complete, administrators have various options they can use to remove or cleanup these mailboxes.

The script obviously does not care about the significance of the individual mailboxes, although certain system mailboxes are excluded from the search. You still have to verify your selection before you take action against any items.

The script can be downloaded for free from here:


Your comments and feedback with regards to these items are always welcome.


Blog Update

Posted by Jean Louw

I am currently busy updating the theme of the blog, and implementing a menu system.

The menu system will give readers easy access to some of the more popular items on my site.

Please be patient while I am updating the site as some of the menu items are still be finalized.

Filed under: Uncategorized No Comments

Monitor the number of items in a list of Public Folders

Posted by Jean Louw

You can use the following basic code, to monitor the number of items in a list of public folders.

My client has a number of workflow processes which rely on public folders, and sometimes if a process stops, the number of items in the public folder will increase. In this script, you can specify the subfolder name, in the root folder and all the folders in that folder will be listed, with the number of items in each.

Replace "folder name" with the name of you main folder that you wish to monitor.

This code uses Outlook to logon and read the folder information, so the account that you are logged onto Outlook with, requires atleast read permission in the public folders which you are monitoring.

$pf = "folder name"
$itemCount = @{Name="Count";expression={foreach-object {($pfroot.folders.Item($pf).folders.item($_.Name).items).count}}}
$pfroot = (new-object -com outlook.application).getNamespace("MAPI").Session.GetDefaultFolder(18)
$pfroot.folders.Item($pf).folders | select Name, $itemCount
Filed under: exchange No Comments

Exchange 2010 Cleanup Utility

Posted by Jean Louw

Good news!

I have completed the update of the Exchange mailbox cleanup tool, for use with Exchange 2010.

I don't have access to a 2010 server at the moment to finalise testing.

I should be able to complete testing next week, and post the updated utility to the site.

Filed under: cleanup, exchange 2 Comments

Find SAMAccountName with trailing space

Posted by Jean Louw

The other day, one of the security guys at a customer had a problem with a reporting package which needs to import objects from Active Directory via LDAP.

The process appeared to import a limited amount of user accounts and then stop.

Feedback provided by the vendor, stated that we had duplicate SAMAccountNames in the domain, which as you know is impossible.

I started investigating the issue, and found a number of objects which, at first appeared to have duplicate SAMAccountName properties. On further investigation, I found that some of these duplicates, were indeed similar, but ended in a trailing space.

I tested this, and it seemed that the ADUC does not allow you to create objects with trailing spaces, so these objects may have been imported from other directories, or old NT4 migrations etc.

I needed a way to find all the objects with trailing spaces in the SAMAccountName property to send the list to the administrators to fix, as this involved some human interaction which I am unable to script.

This seemed easy at first, once you realise that not all SAMAccountName properties are the same length!

The following script will use the Exchange Get-User cmdlet to determine the length of the SAMAccontName property, and then inspect the last character in the string to see if it is a space. If it is, it is added to a variable and reported at the end.

Hopefully this script saves you some time.

$broken = @{Name="Broken";expression={foreach-object {($_.SAMAccountName).ToString().SubString((($_.SAMAccountName.ToString().Length)-1),1).Contains(' ')}}}

$users = Get-User -Resultsize Unlimited

Foreach ($user in $users){
If (($user | Select $broken).broken -eq $True){
[array]$brokenAccounts += $user}

$brokenAccounts | Select Name, SAMAccountName, $broken

Updated: Exchange 2010 Audit Script

Posted by Jean Louw

I have made some updates to the script:

  • Fixed the pipeline issue – You can now use commands like Get-ExchangeServer and pipe that to the script to build a server selection.
  • Embedded the header image into the HTML – This now allows you to display the image even if the server is not connected to the Internet.
  • Changed logical disk information to volume information – This will include volume mount points.
  • Database whitespace – the mailbox database report now displays the whitespace for each database.
  • Move Requests – I have added the ability to display uncleared move requests. This however will currently display on the report for any mailbox server.
  • The version number now correctly displays as 1.1 instead of 4.

Some items I still need to fix:

  • HTML / javascript error with single file report.
  • Colour on the move request section.
  • DAG information and mailbox count by server.
  • Display move requests from current server only.

If you have any additional requests for items you would like to see in the script, or even of you feel the colour scheme is horrible, please let me know.

More complete information, and the download link for the script can be found here:


Exchange 2010 Audit Script – Version 1

Posted by Jean Louw

I have had a couple of requests from a few readers for access to test the Exchange 2010 version of the Audit script, and I made a commitment to have this ready in January 2011. Although the script is nowhere near complete, this is a full working version which can be used to collect information from Exchange 2010 servers.

I have been very busy between work and family commitments, so I will continue to add features as and when time permits.

A couple of bugs I am aware of:

  • You cannot pipe server names to the script yet – this worked on the 2007 script so I need to spend time troubleshooting this.
  • You need to create the test mailboxes manually – refer to my post here for more info: http://www.powershellneedfulthings.com/?p=124
  • You can use the "-output s" parameter to force multiple scans onto a single report. There is a bug in the HTML code which causes the expand function on the HTML report to work incorrectly.

A couple of features I still plan to add:

  • Add volume mount points into the disk report.
  • Database Availability Group reports - I plan to add some reports with regards to the DAG if the server is a member of a DAG.
  • If a database is currently active on a server report on the number of mailboxes and total mailbox count for the current server.
  • Report on uncleared move requests and their status.

I know development is a little slow at the moment, but please be patient, when I start Exchange 2010 in a VM on my current laptop its like I have kicked it in the stomach. I will need to upgrade soon, and I am considering creating a donation option on to enable you guys to contribute to the hardware, but at this stage it is still debatable.

Other than that, I hope you can use the script in your environment, and please send me your feedback and enhancement requests so that I can add them to the wish list.

More complete information, and the download link for the script can be found here:


Automatic Custom Mailbox Limits

Posted by Jean Louw

This little script runs through the Exchange mailboxes and reads the current mailbox size, and sets a new warning limit and send limit for each mailbox, based on the current size.

So basically it looks at the current size of the mailbox, and sets a warning, at current size + 250MB and a send limit, at current size + 350MB. This was a quick workaround for us in an unmanaged environment to quickly establish some method of control without granting over sized limits, in order to accommodate large mailboxes.

This scripts should be run from the Exchange Management Shell.

The code can be copied from here:

$boxes = get-mailbox -resultsize unlimited | Get-MailboxStatistics

Foreach ($box in $boxes)
        $name = $box.DisplayName
        $currentSize = $box.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",", "")
        $WarningQuota = ([int]$currentSize + 262144000)
        $SendQuota = ([int]$currentSize + 367001600)

        Set-Mailbox -Identity $name -IssueWarningQuota $WarningQuota -ProhibitSendQuota $SendQuota

Repair Exchange mailbox display name case

Posted by Jean Louw

We had a problem at one of our customers, where the users were created (by someone else :)) in ALL CAPS. This is more of an annoyance that anything else so I wrote a little script to read the names, and set the case from UPPER CASE to Proper Case.

You obviously have to run this from the Exchange Management Shell.

You can copy the code for the script from here:

$mailboxes = Get-Mailbox

foreach ($mbx in $mailboxes)
        write "..currenntly processing:" $mbx.Name
        $oldName = $mbx.Name.ToString().Split(' ')
        $newName = ($oldName | foreach {$_.Substring(0,1) + $_.SubString(1).ToLower()})
        $mbx | set-mailbox -name $newName -displayname $newName

Creating Test Mailboxes for Mailbox Servers

Posted by Jean Louw

After a couple of requests for more information with regards to the CAS monitoring mailbox, and how to create them, I am going to do a quick cut / paste from Technet:

Create Test Mailboxes for OWA, ActiveSync, and Exchange Web Services Connectivity Monitoring.

The Exchange Server 2007 Management Pack uses cmdlets to test Microsoft Office Outlook Web Access (OWA), Microsoft ActiveSync, and Exchange Web Services connectivity from Client Access servers to Mailbox servers.

These cmdlets require that a test mailbox be created on each Exchange Server 2007 Mailbox server that is to be tested. In this procedure you create test mailboxes for OWA, ActiveSync, and Exchange Web Services connectivity monitoring by using PowerShell to run the New-TestCasConnectivityUser.ps1 script. The appropriate mailbox is created on each Mailbox server by piping in the results of get-mailboxServer.

To create a test mailbox for OWA, ActiveSync, and Exchange Web Services connectivity monitoring

1. On a Mailbox Server, open PowerShell and change directory to the C:\ Program Files\Microsoft\Exchange Server\Scripts folder.
2. Execute the following command: get-mailboxServer | .\new-TestCasConnectivityUser.ps1

Follow the on-screen installation instructions to complete the creation of the test mailbox. When requested, provide a temporary password for the test mailbox. The password must conform to your domain password policy.

This will create a new CAS_ user for each mailbox server. The number following the _ is the GUID of the mailbox server which the test user belongs to.
Remember, this user account is used commands like Test-ActiveSyncConnectivity, Test-OWAConnectivity etc. These mailboxes are also required when using the Exchange 2007 Management Pack for MOM.

These accounts are also required when using my Exchange 2007 Audit Script, as it relies on the test-* cmdlets.