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.
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:
The MIM history has been cleaned ! 🙂
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 :
Microsoft devient la 2e entreprise à valoir 4 000 milliards de dollars Microsoft vient de…
Microsoft banni brutalement un développeur de LibreOffice Microsoft banni brutalement un développeur de LibreOffice, et…
Dropbox Passwords : 5 alternatives après la fermeture de son service Introduction Dropbox Passwords ferme…
Palo Alto Networks rachète Cyberark pour 25 milliards de dollars Introduction Palo Alto Networks rachète…
Microsoft reconnaît ne plus pouvoir garantir la souveraineté des données européennes Coup de tonnerre dans…
Illustration générée par intelligence artificielle Il y a des endroits où l’on se sent bien…