Created
March 10, 2019 08:30
-
-
Save KentNordstrom/a516f75beca562dcf333d173e1b4c802 to your computer and use it in GitHub Desktop.
Clears Run History in FIMSynchronizationService after saving to xml file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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