Powershell Needful Things put that in your pipeline


Updated: Exchange 2010 Mailbox cleanup utility

Posted by Jean Louw

Some users reported that the mailbox server field or the mailbox database field would be empty.

This was a problem with variable that stored the contents. I have patched this, and the new file can be downloaded from here:


Filed under: Uncategorized 2 Comments

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