Created
May 7, 2017 20:02
-
-
Save jhochwald/405c77b4871a5a949a0eaec1e826144c to your computer and use it in GitHub Desktop.
Cleanup the Azure Active Directory Connect Sync
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
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