FIM ScriptBox Item
The script code below clears the run history earlier than or equal to a specific date.
If no parameter is specified, today is used as a specific date.
Optionally, you can specify the number of days from today.
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
Clear-Host
$DeleteDay = Get-Date
If($args.count -gt 0)
{
$DayDiff = New-Object System.TimeSpan $args[0], 0, 0, 0, 0
$DeleteDay = $DeleteDay.Subtract($DayDiff)
}
Write-Host "Deleting run history earlier than or equal to:" $DeleteDay.toString('MM/dd/yyyy')
$lstSrv = @(get-wmiobject -class "MIIS_SERVER" -namespace "root\MicrosoftIdentityIntegrationServer" -computer ".")
Write-Host "Result: " $lstSrv[0].ClearRuns($DeleteDay.toString('yyyy-MM-dd')).ReturnValue
#--------------------------------------------------------------------------------------------------------------------
Trap
Write-Host "`nError: $($_.Exception.Message)`n" -foregroundcolor white -backgroundcolor darkred
Exit
Alternatively, if you prefer to work with a PowerShell module, you can add the following to your module:
01.
<#
02.
.SYNOPSIS
03.
Clears the FIM Run History
04.
.DESCRIPTION
05.
06.
.EXAMPLE
07.
PS> Clear-FIMRunHistory 5
08.
Clears the FIM Run History until 5 days ago
09.
#>
10.
Function Clear-FIMRunHistory {
11.
12.
[CmdletBinding()]
13.
param
14.
(
15.
[Parameter(
16.
Mandatory=$True,
17.
ValueFromPipeline=$true,
18.
ValueFromPipelineByPropertyName=$true)]
19.
[int]$DaysToKeep
20.
)
21.
22.
Begin { }
23.
24.
Process {
25.
26.
27.
If($DaysToKeep -gt 0) {
28.
29.
$DayDiff = New-Object System.TimeSpan $DaysToKeep, 0, 0, 0, 0
30.
31.
32.
Write-Output "Deleting run history earlier than or equal to:" $DeleteDay.toString('MM/dd/yyyy')
33.
34.
Write-Output "Result: " $lstSrv[0].ClearRuns($DeleteDay.toString('yyyy-MM-dd')).ReturnValue
35.
36.
37.
38.
Trap {
39.
Write-Output "`nError: $($_.Exception.Message)`n"
40.
41.
42.
43.
44.
45.
End { }
46.
47.
For more FIM related Windows PowerShell scripts, see the FIM ScriptBox.