Skip to content

Instantly share code, notes, and snippets.

@KentNordstrom
Created March 10, 2019 08:30
Show Gist options
  • Save KentNordstrom/a516f75beca562dcf333d173e1b4c802 to your computer and use it in GitHub Desktop.
Save KentNordstrom/a516f75beca562dcf333d173e1b4c802 to your computer and use it in GitHub Desktop.
Clears Run History in FIMSynchronizationService after saving to xml file.
<#
.SYNOPSIS
Clears run history in FIM Synchronization Service and stores the history.
.PARAMETER dayDiff
The Number of days to keep.
.PARAMETER exportDirectory
The folder where deleted history is saved.
#>
PARAM([int]$dayDiff=7, [string]$exportDirectory="F:\IAM\Logs\RunHistory\")
#Set delete date
$dateNow = Get-Date -Format yyyy-MM-dd_HHmm
$dateDelete = (Get-Date).AddDays(-$dayDiff)
#Export run history before deleting
$filePathName = $exportDirectory + "RunHistory_" + $dateNow + “.xml”
$run = New-Object xml
$finalXML = "<run-history>"
$lstRuns = @(get-wmiobject -class “MIIS_RunHistory” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
$lstRuns | ForEach-Object {
if([datetime]$_.RunEndTime -lt $dateDelete)
{
#Export
$run.LoadXml($_.RunDetails().ReturnValue)
$finalXML += $run.'run-history'.InnerXml
}
}
$finalXML += "</run-history>"
([xml]$finalXML).Save($filePathName)
#Delete the run history before delete date
$lstSrv = @(get-wmiobject -class “MIIS_SERVER” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
$lstSrv[0].ClearRuns($dateDelete.toString(‘yyyy-MM-dd’)).ReturnValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment