'DirSync - Count Total Synchronized Objects' shows total counts of users, groups, contacts, and grand total objects by extracting the FIM SourceAD Connector Space data to an XML file named SourceAD.xml.

When an object makes its way past the Office 365 DirSync filters, they become 'synchronized holograms', and this tool parses the SourceAD.xml looking for synchronized holograms and counts the objects by object type.

The Office 365 Deployment Readiness Tool (DRT) assumes that you have not yet deployed Office 365 DirSync, and it is giving you total object counts, without having the ability to see if those objects will actually make it past the DirSync filters. 'DirSync - Count Total Synchronized Objects' allows you, now that you are in production with DirSync, to see more accurate numbers of objects that have made it past the filters.

 

Important: You should set values for two variables in the tool prior to execution:

Using the $TenantQuota and $Threshold, the tool has built-in, generic messages for when you have either reached quota, are within threshold of your quota, or are safe below your threshold for quota. You can modify the notification part of this tool to cause it to function any way you desire, such as sending an email to your administrative staff when you have reached threshold or have exceeded quota.

 

In order to execute this tool, you must first complete the following:

 

Note: While the tool is executing, you should monitor the size of the SourceAD.xml file, which will be generated in the Bin directory. If you have hundreds of thousands of objects in Active Directory, the XML file has potential to grow large, and you should be concious of your available disk space. Disk space issues for this tool are not typical.

 

PowerShell
Edit|Remove
#------------------------------------------------------------------------------  
 
# Copyright © 2012 Microsoft Corporation.  All rights reserved.  
 
# THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT  
# WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT  
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS  
# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR   
# RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.  
 
#------------------------------------------------------------------------------  
 
# PowerShell Source Code  
 
# NAME:  
#    O365-DirSync-Count-Total-Synchronized-Objects.ps1  
 
# VERSION:  
#    1.0  
 
#------------------------------------------------------------------------------  
#Set values for $TenantQuota and $Threshold prior to running this script. 
#The script file must be placed in the directory where the csexport.exe tool resides 
$ErrorActionPreference = "SilentlyContinue" 
$TenantQuota = 50000 
$Threshold = 2000 
$TotalObjectsSynchronized = 0 
$TotalUsersSynchronized = 0 
$TotalGroupsSynchronized = 0 
$TotalContactsSynchronized = 0 
Write-Host "`n Office 365 DirSync Count Total Synchronized Objects" -ForegroundColor Yellow 
Write-Host "`n This script performs the following actions:" 
Write-Host "`n`t1. Export all objects from the SourceAD Connector Space" 
Write-Host "`t2. Parse the Connector Space output for synchronized objects" 
Write-Host "`t3. Provide a total count of synchronzied objects and a count of each synchronized object type" 
If (!(Test-Path "csexport.exe")) 
{ 
    Write-Host "`n You must run this script from the DirSync bin directory. Exiting...`n" -ForegroundColor Red 
    Exit 
} 
If ((Test-Path "SourceAD.xml"-and (Test-Path "SourceAD-Counts.log")) 
{ 
    Write-Host "`n Previous files found. Remove SourceAD.xml and SourceAD-Counts.log and execute the script again.`n Exiting...`n" -ForegroundColor Red 
    Exit 
} 
elseif (Test-Path "SourceAD.xml") 
{ 
    Write-Host "`n Previous file found. Remove SourceAD.xml and execute the script again.`n Exiting...`n" -ForegroundColor Red 
    Exit 
} 
elseif (Test-Path "SourceAD-Counts.log") 
{ 
    Write-Host "`n Previous file found. Remove SourceAD-Counts.log and execute the script again.`n Exiting...`n" -ForegroundColor Red 
    Exit 
} 
Write-Host "`n Press any key to continue..." 
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") 
Write-Host "`n Exporting objects from the SourceAD Connector Space" -ForegroundColor Green 
.\CSExport.exe SourceAD 
Write-Host "`n Parsing SourceAD.xml for synchronzied objects" -ForegroundColor Green 
[System.Xml.XmlDocument] $xmlDocument = new-object System.Xml.XmlDocument 
$file = resolve-path("SourceAD.xml"$xmlDocument.load($file)  
$csObjects = $xmlDocument.selectnodes("/cs-objects/cs-object"foreach ($csObject in $csObjects) 
{ 
    $synchronizedHologram = $csObject.selectSingleNode("synchronized-hologram") 
    If ($synchronizedHologram.get_HasChildNodes()) 
    { 
        $TotalObjectsSynchronized++ 
        $entry = $synchronizedHologram.selectSingleNode("entry") 
        $primaryObjectClass = $entry.selectSingleNode("primary-objectclass").get_InnerXml() 
        If ($primaryObjectClass -eq "user") 
        { 
            $TotalUsersSynchronized++ 
        } 
        ElseIf ($primaryObjectClass -eq "group") 
        { 
            $TotalGroupsSynchronized++ 
        } 
        ElseIf ($primaryObjectClass -eq "contact") 
        { 
            $TotalContactsSynchronized++ 
        } 
    } 
} 
$Diff = $TenantQuota - $TotalObjectsSynchronized 
 
Write-Host "`n Tenant Quota:`t`t$TenantQuota`n Total Objects:`t`t$TotalObjectsSynchronized`n Total Users:`t`t$TotalUsersSynchronized`n Total Groups:`t`t$TotalGroupsSynchronized`n Total Contacts:`t$TotalContactsSynchronized`n" 
"`n Tenant Quota:`t`t$TenantQuota`n Total Objects:`t`t$TotalObjectsSynchronized`n Total Users:`t`t$TotalUsersSynchronized`n Total Groups:`t`t$TotalGroupsSynchronized`n Total Contacts:`t$TotalContactsSynchronized`n" | Out-File SourceAD-Counts.log -Append 
If (($Diff -le $Threshold-and ($Diff -gt 0)) 
{ 
    Write-Host "`n You are within your threshold value of $Threshold.`n You should file a DirSync quota increase request with support now`n to avoid DirSync failures due to quota exception." 
    "`n You are within your threshold value of $Threshold.`n You should file a DirSync quota increase request with support now`n to avoid DirSync failures due to quota exception." | Out-File SourceAD-Counts.log -Append 
} 
ElseIf ($Diff -le 0) 
{ 
    Write-Host "`n You have hit the DirSync quota limit, and further synchrionization`n with Office 365 will not succeed until either your DirSync quota is increased`n or the number of synchronized objects is reduced." 
    "`n You have hit the DirSync quota limit, and further synchrionization`n with Office 365 will not succeed until either your DirSync quota is increased`n or the number of synchronized objects is reduced." | Out-File SourceAD-Counts.log -Append 
} 
Else 
{ 
    Write-Host "`n You have not yet reached your warning threshold of $Threshold.`n The current difference between your DirSync quota and your total synchronized objects is $Diff." 
    "`n You have not yet reached your warning threshold of $Threshold.`n The current difference between your DirSync quota and your total synchronized objects is $Diff." | Out-File SourceAD-Counts.log -Append 
} 
 
$CleanUp = Read-Host "`n Would you like to remove the SourceAD.xml and SourceAD-Counts.log files? (Y/N)" 
If ($CleanUp -eq "Y") 
{ 
    Remove-Item SourceAD.xml -Force 
    Remove-Item SourceAD-Counts.log -Force 
} 
Write-Host "`n Done!`n" -ForegroundColor Green