PowerShell script for FIM and ILM to save Run Details

In order to better log errors in PowerShell, I wanted to export the results of the management agent run to an XML file.

The idea is to then leverage this XML file to parse out the objects that errored and save their state at the time of the error, as well as any updates that were trying to be performed.

With the help of two TechNet articles, I cobbled together the following. It’s just a start, but I was happy it worked!

# RunMA.ps1
# Accepts MAName and Run Profile Name with optional ILM Servername
# Returns errorlevel 0 on success, 1 on any failure
#
# Setup the argument parameters
# Declare the default ILM server as local
param([string]$MAName,[string]$RunProfileName,[string]$ILMServerName = “.”)

# Get the WMI Server object
$curMA = @(get-wmiobject -class “MIIS_ManagementAgent” -namespace “root\MicrosoftIdentityIntegrationServer” -computername $ILMServerName -filter “Name=’$MAName'”)
# Validate that the MA exists
if($curMA.count -eq 0){throw “MA not found”}

Write-Host “`nStarting $RunProfileName on $MAName”
$Status = $($curMA[0].Execute($RunProfileName).ReturnValue)
Write-Host “Result: $Status`n”

$runDetails = $curMA[0].RunDetails().ReturnValue

$doc = New-Object System.Xml.XmlDocument

$doc.LoadXml($runDetails)
$dNow = Get-Date -format “yyyy-MM-dd HH-mm”

Write-Host($dNow)
$doc.Save(“C:\FIMLogs\”+ $MAName + ” ” + $RunProfileName + ” ” + $dNow +”.xml”)

#————————————————————————————————–
trap
{
Write-Host “`nError: $($_.Exception.Message)`n” -foregroundcolor white -backgroundcolor darkred
exit 1
}
#————————————————————————————————–

if($Status -ne “success”){exit 1}

Thanks to the following forum posts:

http://social.technet.microsoft.com/Forums/en-US/identitylifecyclemanage…

http://social.technet.microsoft.com/Forums/en-US/ilm2/thread/cce395ad-e3…

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s