Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Making sense of AD Replication schedules pt 2
function Get-ADReplicationSchedule
{
[CmdletBinding()]
param
(
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
[System.DirectoryServices.ActiveDirectory.ActiveDirectorySchedule]$ReplicationSchedule,
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory = $true)]
[string]$DistinguishedName
)
begin
{
$returnValues = @()
}
process
{
Write-Verbose -Message ('Processing {0}' -f $DistinguishedName)
$returnValue = New-Object PSObject -Property @{
DistinguishedName = $DistinguishedName
Schedule = @()
}
foreach ( $day in [System.Enum]::GetValues([System.DayOfWeek]))
{
$scheduleObject = New-Object psobject -Property @{
DayOfWeek = $day
Interval = @()
}
$scheduleObject | Add-Member -MemberType ScriptProperty -Name EnabledInterval -Value { $this.Interval | Where-Object Enabled }
$scheduleObject | Add-Member -MemberType ScriptProperty -Name DisabledInterval -Value { $this.Interval | Where-Object Enabled -eq $false }
foreach ( $hour in 0..23)
{
foreach ( $interval in 0..3)
{
$intervalObject = New-Object PSObject -Property @{
IntervalStart = New-TimeSpan -Hours $hour -Minutes ($interval * 14.75)
IntervalEnd = New-TimeSpan -Hours $hour -Minutes (($interval + 1) * 14.75)
Enabled = $ReplicationSchedule.RawSchedule[[int]$day, $hour, $interval]
}
$scheduleObject.Interval += $intervalObject
}
}
$returnValue.Schedule += $scheduleObject
}
$returnValues += $returnValue
}
end
{
$returnValues
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment