Skip to content

21bshwjt/SysVol-D4-PowerShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

97 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Force DFSR SysVol Replication via PowerShell

Automate the D4/D2 SysVol replication recovery process across all Domain Controllers β€” no manual ADSIEDIT required.

PowerShell Active Directory Windows Server License


πŸ“– Official Microsoft KB β†’ Force Authoritative & Non-Authoritative Synchronization for DFSR-Replicated Sysvol


πŸ“‹ Table of Contents

# Step Description
1 Stop DFSR Service Set startup to Manual & stop on all DCs
2 Verify Service Status Confirm service is stopped across all DCs
3 Manual ADSIEDIT Reference Reference for manual attribute changes
4 Set PDC as Authoritative Automate ADSIEDIT changes on PDC
5 Set All Other DCs Set msDFSR-Enabled=FALSE on non-PDC DCs
6 Force AD Replication Sync changes across the domain
7 Start DFSR on PDC Bring up replication on the authoritative DC
8 Event ID 4114 Verify sysvol is no longer replicating
9 Re-enable PDC Set msDFSR-Enabled=TRUE on PDC
10 Force AD Replication Again Push updated attributes across domain
11 DFSRDIAG on PDC Trigger DFSR poll on authoritative DC
12 Event ID 4602 Confirm D4 initialization complete
13 Start DFSR on Other DCs Bring up replication on all remaining DCs
14 Re-enable All Other DCs Set msDFSR-Enabled=TRUE on non-PDC DCs
15 DFSRDIAG on Non-Auth DCs Trigger DFSR poll on all non-authoritative DCs
16 Restore Service to Automatic Return DFSR to automatic startup on all DCs
17 Verify Final Status Confirm all DCs are healthy
18 SysVol Health Check Validate SysVol state = 4 (Normal) on all DCs
19 Verify ADSIEDIT Attributes Confirm msDFSR-options reset to 0

⚠️ Use Cases

- 1. Missing SysVol / Netlogon folders on one or more Domain Controllers
- 2. GPO inconsistencies across Domain Controllers in the domain

βœ… Prerequisites

Run all scripts in sequence from the PDC Emulator with an elevated PowerShell session.

Requirement Detail
πŸ–₯️ Run Location PDC Emulator
πŸ”‘ Permissions Domain Admins
πŸ“¦ Module Active Directory PowerShell Module
πŸ“‚ Setup Copy the Scripts folder to the PDC
πŸ”’ Script Order Run in sequence β€” scripts 3, 8 & 12 are intentionally absent (manual/event steps)
βœ”οΈ Post-Validation Scripts 18 and 19 are for post-validation only

πŸ”΅ Step 1 β€” Stop DFSR Service on All DCs

Set the DFS Replication service startup type to Manual and stop it on all domain controllers.

$DCs = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

$DCs | ForEach-Object -Process {
    try {
        Invoke-Command -ComputerName $PSItem -ScriptBlock {
            Set-Service -Name 'DFSR' -StartupType Manual -Verbose
            Stop-Service -Name 'DFS Replication' -Force -Verbose
        } -ErrorAction Stop
    } catch {
        Write-Error "Failed to modify DFSR service on $PSItem | Error: $_"
    }
}

πŸ”΅ Step 2 β€” Verify DFSR Service Status

Confirm the service is stopped and set to Manual on all DCs before proceeding.

$DCs = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

$GetoBj = Foreach ($DC in $DCs) {
    Invoke-Command -ComputerName $DC {
        [PSCustomObject]@{
            DomainController = ($env:COMPUTERNAME).ToUpper()
            ServiceName      = (Get-Service -Name DFSR).Name
            Status           = (Get-Service -Name DFSR).Status
            StartType        = (Get-Service -Name DFSR).StartType
        }
    }
}
$GetoBj | Select-Object -Property DomainController, ServiceName, Status, StartType

🟑 Step 3 β€” Manual ADSIEDIT Reference

ℹ️ This step is handled automatically in Step 4. Shown here for reference only.

In ADSIEDIT.MSC, modify the following DN on the PDC Emulator:

CN=SYSVOL Subscription,CN=Domain System Volume,CN=DFSR-LocalSettings,CN=<ServerName>,OU=Domain Controllers,DC=<domain>
Attribute Value
msDFSR-Enabled FALSE
msDFSR-options 1

πŸ”΅ Step 4 β€” Set PDC as Authoritative (Automated)

Automatically apply the ADSIEDIT changes to the PDC Emulator via PowerShell.

$PDCNameFull = (Get-ADDomain).PDCEmulator
$PDCName     = $PDCNameFull -split '\.' | Select-Object -First 1
$domain      = (Get-ADDomain).DistinguishedName
$dn          = "CN=SYSVOL Subscription,CN=Domain System Volume,CN=DFSR-LocalSettings,CN=$PDCName,OU=Domain Controllers,$domain"

Set-ADObject -Identity $dn -Replace @{
    "msDFSR-Enabled" = $False
    "msDFSR-options" = 1
} -Verbose

πŸ”΅ Step 5 β€” Set msDFSR-Enabled = FALSE on All Other DCs

Disable DFSR replication on all non-PDC domain controllers.

$domain = (Get-ADDomain).DistinguishedName
$DCs    = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

foreach ($DC in $DCs) {
    $dn = "CN=SYSVOL Subscription,CN=Domain System Volume,CN=DFSR-LocalSettings,CN=$DC,OU=Domain Controllers,$domain"
    Set-ADObject -Identity $dn -Replace @{
        "msDFSR-Enabled" = $False
    } -Verbose
}

πŸ”΅ Step 6 β€” Force AD Replication

Push all attribute changes across the entire domain and validate replication success.

repadmin /syncall /A /e /P /d /q

πŸ”΅ Step 7 β€” Start DFSR on PDC

Start the DFS Replication service only on the PDC Emulator at this stage.

$PDCNameFull = (Get-ADDomain).PDCEmulator
$PDCName     = $PDCNameFull -split '\.' | Select-Object -First 1

Invoke-Command -ComputerName $PDCName {
    Start-Service -Name 'DFS Replication' -Verbose
}

🟑 Step 8 β€” Event ID 4114

πŸ“‹ No script required. Open Event Viewer β†’ DFS Replication on the PDC.

βœ… You should see Event ID 4114 β€” confirming SysVol replication is no longer being replicated (expected at this stage).


πŸ”΅ Step 9 β€” Set msDFSR-Enabled = TRUE on PDC

Re-enable DFSR on the PDC Emulator to trigger the authoritative (D4) restore.

$PDCNameFull = (Get-ADDomain).PDCEmulator
$PDCName     = $PDCNameFull -split '\.' | Select-Object -First 1
$domain      = (Get-ADDomain).DistinguishedName
$dn          = "CN=SYSVOL Subscription,CN=Domain System Volume,CN=DFSR-LocalSettings,CN=$PDCName,OU=Domain Controllers,$domain"

Set-ADObject -Identity $dn -Replace @{
    "msDFSR-Enabled" = $True
} -Verbose

πŸ”΅ Step 10 β€” Force AD Replication Again

Sync the updated attributes across the domain once more.

repadmin /syncall /A /e /P /d /q

πŸ”΅ Step 11 β€” Run DFSRDIAG POLLAD on PDC

Force the PDC to poll Active Directory and apply the new DFSR configuration.

DFSRDIAG POLLAD

🟑 Step 12 β€” Event ID 4602

πŸ“‹ No script required. Open Event Viewer β†’ DFS Replication on the PDC.

βœ… You should see Event ID 4602 β€” confirming SysVol replication has been initialized. The PDC has completed the D4 authoritative restore.


πŸ”΅ Step 13 β€” Start DFSR on All Non-Authoritative DCs

Start the DFS Replication service on all remaining domain controllers.

$DCs = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

$DCs | ForEach-Object -Process {
    Invoke-Command -ComputerName $PSItem {
        Start-Service -Name 'DFS Replication' -Verbose
    }
}

πŸ“‹ After starting, check Event Viewer β†’ DFS Replication on each DC for Event ID 4114 (expected).


πŸ”΅ Step 14 β€” Set msDFSR-Enabled = TRUE on All Other DCs

Re-enable DFSR replication on all non-authoritative domain controllers.

$domain = (Get-ADDomain).DistinguishedName
$DCs    = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

foreach ($DC in $DCs) {
    $dn = "CN=SYSVOL Subscription,CN=Domain System Volume,CN=DFSR-LocalSettings,CN=$DC,OU=Domain Controllers,$domain"
    Set-ADObject -Identity $dn -Replace @{
        "msDFSR-Enabled" = $True
    } -Verbose
}

πŸ”΅ Step 15 β€” Run DFSRDIAG POLLAD on All Non-Auth DCs

Force all non-authoritative DCs to poll AD and pull SysVol content from the PDC.

$servers     = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name
$PDCNameFull = (Get-ADDomain).PDCEmulator
$PDCName     = $PDCNameFull -split '\.' | Select-Object -First 1

# Exclude PDC from the list
$servers = $servers | Where-Object { $_ -ne $PDCName }

$servers | ForEach-Object -Process {
    Invoke-Command -ComputerName $PSItem { DFSRDIAG POLLAD -Verbose }
}

πŸ”΅ Step 16 β€” Restore DFSR Startup Type to Automatic

Return the DFSR service to Automatic startup on all domain controllers.

$DCs = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

$DCs | ForEach-Object -Process {
    Invoke-Command -ComputerName $PSItem {
        Set-Service -Name 'DFSR' -StartupType Automatic -Verbose
    }
}

πŸ”΅ Step 17 β€” Verify Final DFSR Service Status

Confirm DFSR is Running and set to Automatic on all DCs.

$DCs = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

$GetoBj = foreach ($DC in $DCs) {
    try {
        Invoke-Command -ComputerName $DC -ScriptBlock {
            [PSCustomObject]@{
                DomainController = $env:COMPUTERNAME.ToUpper()
                ServiceName      = (Get-Service -Name DFSR -ErrorAction Stop).Name
                Status           = (Get-Service -Name DFSR -ErrorAction Stop).Status
                StartType        = (Get-Service -Name DFSR -ErrorAction Stop).StartType
            }
        }
    } catch {
        [PSCustomObject]@{
            DomainController = $DC.ToUpper()
            ServiceName      = "DFSR"
            Status           = "Error: $($Error[0].Exception.Message)"
            StartType        = "Unknown"
        }
    }
}
$GetoBj | Select-Object -Property DomainController, ServiceName, Status, StartType

🟒 Step 18 β€” SysVol Health Check (Post-Validation)

+ Expected "State" value on all DCs is 4 (Normal) after replication completes.
State Value Meaning
0 Uninitialized
1 Initialized
2 Initial Sync
3 Auto Recovery
βœ… 4 Normal ← Expected
5 In Error
$servers = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

foreach ($server in $servers) {
    try {
        $result = Get-WmiObject -Namespace "root\microsoftdfs" -Class "dfsrreplicatedfolderinfo" `
            -ComputerName $server -Filter "replicatedfoldername='SYSVOL share'" |
            Select-Object @{Name = 'DomainController'; Expression = { $_.MemberName } },
                          ReplicationGroupName, ReplicatedFolderName, State
        if ($result) {
            $result
        } else {
            Write-Warning "No DFSR info found on $server for 'SYSVOL share'."
        }
    } catch {
        Write-Warning "Error querying $server : $_"
    }
}

🟒 Step 19 β€” Verify ADSIEDIT Attribute Values (Optional)

+ msDFSR-options will revert automatically from "1" back to "0" on the PDC after some time.
$domain = (Get-ADDomain).DistinguishedName
$DCs    = Get-ADGroupMember -Identity "Domain Controllers" | Select-Object -ExpandProperty Name

$Objs = Foreach ($DC in $DCs) {
    Get-ADObject -Filter { Name -eq "SYSVOL Subscription" } `
        -SearchBase "CN=Domain System Volume,CN=DFSR-LocalSettings,CN=$DC,OU=Domain Controllers,$domain" `
        -Properties DistinguishedName, msDFSR-Enabled, msDFSR-options |
        Select-Object DistinguishedName, msDFSR-Enabled, msDFSR-options
}

foreach ($Obj in $Objs) {
    $msDFSR_options = $Obj.'msDFSR-options'
    if ([string]::IsNullOrWhiteSpace($msDFSR_options)) { $msDFSR_options = "<not set>" }

    [PSCustomObject]@{
        DomainController = ($Obj.DistinguishedName -split ",")[3].Substring(3)
        "msDFSR-Enabled" = $Obj.'msDFSR-Enabled'
        "msDFSR-options" = $msDFSR_options
    }
}

πŸ” Process Flow at a Glance

Stop DFSR (All DCs)
       ↓
Set PDC β†’ msDFSR-Enabled=FALSE, msDFSR-options=1
       ↓
Set All Other DCs β†’ msDFSR-Enabled=FALSE
       ↓
Force AD Replication
       ↓
Start DFSR on PDC β†’ [Event ID 4114]
       ↓
Set PDC β†’ msDFSR-Enabled=TRUE
       ↓
Force AD Replication
       ↓
DFSRDIAG POLLAD on PDC β†’ [Event ID 4602 β€” D4 Complete βœ…]
       ↓
Start DFSR on All Other DCs β†’ [Event ID 4114 on each]
       ↓
Set All Other DCs β†’ msDFSR-Enabled=TRUE
       ↓
DFSRDIAG POLLAD on All Non-Auth DCs
       ↓
Restore DFSR to Automatic (All DCs)
       ↓
Post-Validation: SysVol State = 4 βœ…

πŸ‘€ Author

Biswajit Biswas (a.k.a. bshwjt)

LinkedIn Email GitHub


πŸ“Œ All scripts are provided as-is. Always test in a non-production environment first.

Maintained PowerShell

About

Force authoritative synchronization for DFSR-replicated SysVol Replication using PowerShell

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors