-
Notifications
You must be signed in to change notification settings - Fork 6
/
Invoke-ADSDPropagation.ps1
53 lines (47 loc) · 2.02 KB
/
Invoke-ADSDPropagation.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Function Invoke-ADSDPropagation{
<#
.SYNOPSIS
Invoke a SDProp task on the PDCe.
.DESCRIPTION
Make an LDAP call to trigger SDProp.
.EXAMPLE
Invoke-ADSDPropagation
By default, RunProtectAdminGroupsTask is used.
.EXAMPLE
Invoke-ADSDPropagation -TaskName FixUpInheritance
Use the legacy FixUpInheritance task name for Windows Server 2003 and earlier.
.PARAMETER TaskName
Name of the task to use.
- FixUpInheritance for legacy OS
- RunProtectAdminGroupsTask for recent OS
.INPUTS
.OUTPUTS
.NOTES
You can track progress with:
Get-Counter -Counter '\directoryservices(ntds)\ds security descriptor propagator runtime queue' | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue
.LINK
http://ItForDummies.net
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,
HelpMessage='Name of the domain where to force SDProp to run',
Position=0)]
[ValidateScript({Test-Connection -ComputerName $_ -Count 2 -Quiet})]
[String]$DomainName = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name,
[ValidateSet('RunProtectAdminGroupsTask','FixUpInheritance')]
[String]$TaskName = 'RunProtectAdminGroupsTask'
)
try{
$DomainContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext('domain',$DomainName)
$DomainObject = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($DomainContext)
Write-Verbose -Message "Detected PDCe is $($DomainObject.PdcRoleOwner.Name)."
$RootDSE = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$($DomainObject.PdcRoleOwner.Name)/RootDSE")
$RootDSE.UsePropertyCache = $false
$RootDSE.Put($TaskName, "1") # RunProtectAdminGroupsTask & fixupinheritance
$RootDSE.SetInfo()
}
catch{
throw "Can't invoke SDProp on $($DomainObject.PdcRoleOwner.Name) !"
}
}