Report your Exchange Offline Address Book Sizes using Powershell
Just a quick post for Saturday. If you'd like to check your OAB sizes, here's a quick script that allows you to do so quickly and easily. This could be useful to keep track of the space used over time, check all OAB replicas are the same size or to quickly check that the sizes have changes after manually running the Update-OfflineAddressBook cmdlet.
There's few pre-requisites, You need to be on a machine that has at least read access to the C$ shares on the Client Access Servers hosting the OAB folders along with access to get information about the Offline Address Book and OAB Virtual Directories.
Once those pre-reqs are fulfilled, usage is simple:
The output should look similar to this:
You can of course pipe the output and filter it, i.e.
The Get-OABSizes.ps1 Script
# Get-OABSizes.ps1
# Fetches the total file size of each copy of each offline address book
#
# Steve Goodman
#
# Retrieve all OABs
$OABs = Get-OfflineAddressBook
# Cycle through each OAB
foreach ($OAB in $OABs)
{
# Cycle through each OAB Virtual Directory for the current OAB
foreach ($OABVirtualDirectory in $OAB.VirtualDirectories)
{
# Get the actual OAB Virtual Directory properties
$OABVirtualDirectory = Get-OabVirtualDirectory -Identity $OABVirtualDirectory;
# Retrieve the folder local to the CAS that hosts the OAB, and append the Guid of this OAB
$LocalOABPath = "$($OABVirtualDirectory.Path)\$($OAB.Guid)";
# Get the UNC path used to get to the hidden C$ share on the CAS
$BaseUNCPath = "\\$($OABVirtualDirectory.Server)\C$";
# Replace the local path with the UNC path to the CAS server
$UNCOABPath = $LocalOABPath.Replace("C:",$BaseUNCPath);
# Get the directory listing of the folder hosting the OAB
$OABItems = Get-ChildItem -Path $UNCOABPath
# Calculate the total size of the folder hosting the OAB, in bytes
[int]$TotalBytes = ($OABItems | Measure-Object -Property Length -Sum).Sum;
# Convert the total size in bytes to kilobytes
[int]$TotalKBytes = $TotalBytes/1024;
# Build the output object for this copy of the OAB and output it
$Output = New-Object Object
$Output | Add-Member NoteProperty Server $OABVirtualDirectory.Server;
$Output | Add-Member NoteProperty Name $OABVirtualDirectory.Name;
$Output | Add-Member NoteProperty OABName $OAB.Name;
$Output | Add-Member NoteProperty OABSizeKB $TotalKBytes;
$Output
}
}
Hope you find this useful.
TechNet Wiki – Exchange 2010 Powershell Scripting Resources
If you've ever wondered how to get started with Exchange Powershell scripting, or have looked for ways to find out more information, bulk modify or automate your environment then hopefully you'll find this article I've recently posted on the Exchange 2010 section on the TechNet Wiki useful.
The Exchange Management Shell isn't just for large enterprises with large teams. Scripting Exchange can provide benefits to even administrators of small, single server environments; for example to provide reports on recent changes to the environment, collate patch levels or to make laborious tasks simple.
The article provides information about how to get started, where to find useful resources and how to get help if you get stuck, along with information about how to take things to the next level once you've found your bearings. As it's a wiki, feel free to add your own favourite resources and Exchange Powershell related blogs too!
Exchange 2010 Powershell Scripting Resources
Scripted Shared Mailbox Creation on Exchange 2007/2010
I thought I’d share one of the scripts we use for automating creation of Shared Mailboxes within our organisation. One of the more laborious parts of creating shared mailboxes after creation of the actual Mailbox, is setting the manager, department, and granting a (possibly long) list of users permissions and send-as rights.
This script is a simple Powershell script that takes some of the pain out of the process. The assumption is that you want to achieve the following:
- Create a shared mailbox with a common alias, email address and username, checking input values before attempting to create the mailbox.
- You would like to specify the Department at creation and use the Department AD attribute to generate Address Lists
- You would like to attach a user as Manager for the Shared Mailbox so it is clear who manages it
You can use the script with Parameters – e.g:
.\New-SharedMailbox.ps1 -Department "Human Resources" -Alias hr_test -DisplayName "HR Test" -Manager managerusername -Usernames "username1,username2"
–Department is the text to use for the department attribute
–Alias is the Email Alias & Username
–DisplayName is the friendly textual name shown to users and recipients
–Manager is the username, UPN or email address of the Manager (who will have full access + send as rights along with being set as Manager)
–Usernames is a comma separated list of usernames of people who should also have full access and send-as rights.
Or - if that isn’t your thing, then you can just run the script without any options, and it will prompt you as you go along for the parameters. If you are using the Department attribute for Address List generation, you can hit enter when prompted for the department to get a list of in-use departments. As you go along values will be checked, to ensure the Alias and Display Name aren’t in use by Mailboxes or Mail Users and that the Manager and Usernames are attached to valid Mailboxes.
Before you get started with script it does need a little setup.
The setup is fairly straightforward, though. Open the script in a text editor, and change the values for $DomainController, $OU, $UPNDomain and $MailboxDatabase to values appropriate for your organisation. It goes without saying you should test this out on something not connected to your production environment. I won’t take any responsibility for any damage you do with this!
I’ve obviously taken some stuff out that is specific to our organisation (for example, we have a switch statement to determine the mailbox database and exchange server; and also generate Unix information) and if this almost does what you want let me know and I’ll be happy to help you customise it.
Download New-SharedMailbox.ps1


