Categories: EnglishWindows Server

Clean-up MIM History in PowerShell

Microsoft-MIMMicrosoft-MIM

By default, you can see status of previous Management Agents executions in the History tab in Synchronization Service Manager. But, if you execute some Managent Agents very often it will necessarily increase the amount of logs that will be kept by MIM.

2016-03-26_15h42_542016-03-26_15h42_54

To clear and clean-up MIM history automatically in PowerShell, you can use the following function:

function CleanUpMimHistory ()
{
 $computerName = "."
 $MIMHistory = Get-Wmiobject -Class 'MIIS_RunHistory' -namespace “root\MicrosoftIdentityIntegrationServer”
 $MIMServer = Get-Wmiobject -Class "MIIS_Server" -Namespace "root\MicrosoftIdentityIntegrationServer" -ComputerName $computerName -ErrorAction SilentlyContinue

 # I configured the number of days in a separated XML file but for the example we will set up in the function
 $daysBeforeHistoryPurge = 15 #$XmlDocument.MIM.'global-settings'.daysBeforeHistoryPurge 

 $endingBefore = [System.DateTime]::UtcNow.AddDays(-$daysBeforeHistoryPurge).ToString("yyyy-MM-dd HH:mm:ss.fff")

 # Clear MA runs History
 try
 {
 Write-Host ("[DEBUG] - Clearing MIM run history older than " + $daysBeforeHistoryPurge + " days")
 $clearRunHistory = $MIMServer.ClearRuns($endingBefore) # Purging
 Write-Host ("[DEBUG] - Status of the clearing operation : " + $clearRunHistory.ReturnValue)
 }
 catch
 {
 # Problem : displaying the Exception and Breaking the execution if needed
 Write-Host $($_.Exception.Message)
 Write-Host ("[ERROR] - Problem during the clear of the MIM runs history")
 Break
 }
}

In the below example, I normally set up the number of days for which I will keep the logs in a dedicated XML files that containing all my MIM configuration depending on my Management Agents. But this is only for my configuration, so for the example I have set up the number of days directly in the function (up to you to change and adapt according to your needs).

After a short moment, you will notice the following in the PowerShell output:

2016-03-26_15h46_522016-03-26_15h46_52

The MIM history has been cleaned ! 🙂

2016-03-26_15h48_332016-03-26_15h48_33

To go further, it’s now up to you to automatically call this script on regularly basis (with Task Scheduler for example).

To clear thanks to the GUI, follow this link.

Available to download :

Share
Published by
thibault

Recent Posts

Google Chrome bloque uBlock Origin : Quand la sécurité masque des intérêts commerciaux

Google Chrome bloque uBlock Origin : Quand la sécurité masque des intérêts commerciaux Depuis début…

6 jours ago

Vie privée préservée : l’Assemblée rejette les portes dérobées

Vie privée préservée : l'Assemblée rejette les portes dérobées L'Assemblée nationale française rejette la mise…

1 semaine ago

Microsoft abandonne Remote Desktop Connection au profit de la Windows App

Microsoft abandonne Remote Desktop Connection au profit de la Windows App Microsoft a récemment annoncé…

2 semaines ago

Google contraint de vendre Chrome après une décision antitrust

Google contraint de vendre Chrome après une décision antitrust Le département américain de la Justice…

2 semaines ago

L’évolution de la technologie et le déclin des plateformes numériques

Illustration - Image générée par IA L'avancement technologique a radicalement transformé notre façon de communiquer,…

2 semaines ago

Discord prépare son entrée en Bourse : une nouvelle ère pour la plateforme des gamers

Depuis sa création en 2015, Discord est devenue une plateforme incontournable dans le monde du…

3 semaines ago