Skip to content

Instantly share code, notes, and snippets.

@jhochwald
Created May 7, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhochwald/405c77b4871a5a949a0eaec1e826144c to your computer and use it in GitHub Desktop.
Save jhochwald/405c77b4871a5a949a0eaec1e826144c to your computer and use it in GitHub Desktop.
Cleanup the Azure Active Directory Connect Sync
function Clear-AADCSyncRuns
{
<#
.SYNOPSIS
Cleanup the Azure Active Directory Connect Sync
.DESCRIPTION
Cleanup the Azure Active Directory Connect Sync
.PARAMETER DaysToKeep
Clear runs older than given value. 0 means only today.
.EXAMPLE
PS C:\> Clear-AADCSyncRuns
# Clear runs older then 2 days
.EXAMPLE
PS C:\> Clear-AADCSyncRuns -DaysToKeep 0
# Clear runs older then today.
.NOTES
Works with DirSync, or newer.
#>
[CmdletBinding()]
[OutputType([string])]
param
(
[Parameter(ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 1)]
[ValidateNotNullOrEmpty()]
[Alias('Days')]
[int]
$DaysToKeep = 2
)
Process
{
# Get the local DirSync (FIM) server object
$DirSync = (Get-WmiObject -Class 'MIIS_SERVER' -Namespace 'root\MicrosoftIdentityIntegrationServer')
}
End
{
# Clear runs older than X days
$ResultTMP = ($DirSync.ClearRuns([DateTime]::Today.AddDays(- $DaysToKeep)))
# Transform the result
if ($ResultTMP)
{
[string]$Result = $ResultTMP.ReturnValue
}
else
{
[string]$Result = 'Unknown'
}
# Return
Return $Result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment