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:

.\Get-OABSizes.ps1

The output should look similar to this:

image

You can of course pipe the output and filter it, i.e.

.\Get-OABSizes.ps1 | Where {$_.Server -like "EXCH-CA*"} | Select Server,OABSizeKB

image

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
}
}

Download Get-OABSizes.ps1

Hope you find this useful.

2 thoughts on “Report your Exchange Offline Address Book Sizes using Powershell

  1. Hello Steve, I found your script at https://gallery.technet.microsoft.com/office/Report-your-Exchange-a1aa535b. This is a nice piece of work, thank you for this!
    Unfortunately, I found a small error when the OABs are located on another drive than C:.
    I suggest following code:

    # Retrieve UNC path to the CAS server and the folder local to the CAS that hosts the OAB, and append the Guid of this OAB
    $OABPath = “\\$($OABVirtualDirectory.Server)\$($OABVirtualDirectory.Path)\$($OAB.Guid)”;
    # Replace the local path : sign with the $ sign used in UNC paths
    $OABPath = $OABPath.Replace(“:\”,”$\”);

  2. Pingback: Tweets that mention Report your Exchange Offline Address Book Sizes using Powershell | Steve Goodman's Tech Blog -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *