FIM2010–Getting Accurate Run Statistics using WMI

I was recently working on an email body that was being sent to a client when his sync schedule ran during the day. The run script that I had created captured the statistics that the WMI object provided. So, I had the following basic code (lines numbered for clarity):

  1. $miisWmiObject = get-WMIObject – class MIIS_ManagementAgent – namespace root/MicrosoftIdentityIntegrationServer – filter “Name=”Text Management Agent”
  2. $MiisWmiObject.Execute(“Full Import”)
  3. [int] $add = $MiisWmiObject.NumImportAdd().ReturnValue
  4. [int]$mod = $MiisWmiObject.NumImportUpdate().ReturnValue
  5. [int]$del = $MiisWmiObject.NumImportDelete().ReturnValue

(Then there were lines of code to put the values in the file in a nice and neat manner.)

The email body had there being 196 adds, 2 modifies and 0 deleted. This was strange because the operations log showed that no changes had been made at all. It was all zeros across the board. Where did these numbers come from?

On closer inspection, the statistics actually reflect the pending imports or connectors that have not yet been connected to the metaverse. Looking at the connector space of the MA showed that there were 196 pending import additions and 2 pending import modifications.

Well, those values are not what I need to report on. I need to actual statistics as being shown by the operations tab of the screen. That is when I found the “RunDetails()” method that is part of the “MIIS_ManagementAgent class. This returns the full run details in xml format (see this link for an example of the format –> http://msdn.microsoft.com/en-us/library/windows/desktop/ms698398(v=vs.100).aspx). Ah ha! I could drill down into the XML returned by that command to find my information.

To get the staging statistics, the following code was required (modified the code up top so you can see the changes):

  1. $miisWmiObject = get-WMIObject – class MIIS_ManagementAgent – namespace root/MicrosoftIdentityIntegrationServer – filter “Name=”Text Management Agent”
  2. $MiisWmiObject.Execute(“Full Import”)
  3. [xml]$runHistory = $MiisWmiObject.RunDetails().ReturnValue
  4. $stagingStats = $runHistory.’run-history’.’run-details’.’step-details’.’staging-counters’
  5. [int] $add = $stagingStats.’stage-add’.’#text’
  6. [int]$mod = $stagingStats.’stage-update’.’#text’
  7. [int]$del = $stagingStats.’stage-delete’.’#text’
  8. [int]$nochange = $stagingStats.’stage-no-change’.’#text’

Note that on line 3, you have to cast the “ReturnValue” into XML. Otherwise, it is parsed as a string and the commands will not work. Also, all the nodes with the “-“ and “#” characters have to be surrounded by the single quote or PowerShell will not parse it and you’ll get one of the red-errors of death.

I was also happy to show that I could return the total of entries that were not modified as well (line 8) as that made the report even more completed.

There are other nodes in the xml that you can use. I also used the “export-counters” node to get the different export statistics. Replace the “staging-counters” with export counts in line 4 of the second block of code to get these counters. It includes nodes with information for export-add, export-update, export-rename, export-delete, export-failure and export-delete-add.

Advertisements
This entry was posted in Forefront Identity Manager 2010. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s