Skip to content

Instantly share code, notes, and snippets.

@nyanhp
Created February 22, 2018 09:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nyanhp/d9a1b591b5a69e300f640d53a02e0b44 to your computer and use it in GitHub Desktop.
Save nyanhp/d9a1b591b5a69e300f640d53a02e0b44 to your computer and use it in GitHub Desktop.
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