$domain = 'cascades.local'
$srv = 'CS-SERVER'
$sysvol = "\\$srv\SYSVOL\$domain\Policies"

# Read the unlinked CSC - Folder Redirection Registry.xml
$gpo = Get-GPO -Name 'CSC - Folder Redirection' -Domain $domain
$guid = "{$($gpo.Id.ToString().ToUpper())}"
$xmlPath = "$sysvol\$guid\User\Preferences\Registry\Registry.xml"
Write-Output "=== CSC - Folder Redirection Registry.xml ==="
[System.IO.File]::ReadAllText($xmlPath) | Write-Output

Write-Output ""
Write-Output "=== LE GPO GPC attributes (AD) ==="
$gpoLE = Get-GPO -Name 'CSC - Folder Redirection (LE)' -Domain $domain
$leGuid = "{$($gpoLE.Id.ToString().ToUpper())}"
$gpcObj = Get-ADObject -Filter { Name -eq $leGuid } -Properties 'gPCUserExtensionNames','gPCMachineExtensionNames','versionNumber','gPCFileSysPath' -SearchBase "CN=Policies,CN=System,DC=cascades,DC=local" -EA SilentlyContinue
if ($gpcObj) {
    Write-Output "  gPCUserExtensionNames: $($gpcObj.gPCUserExtensionNames)"
    Write-Output "  gPCMachineExtensionNames: $($gpcObj.gPCMachineExtensionNames)"
    Write-Output "  versionNumber: $($gpcObj.versionNumber)"
    Write-Output "  gPCFileSysPath: $($gpcObj.gPCFileSysPath)"
} else { Write-Output "  GPC object not found" }

Write-Output ""
Write-Output "=== LE GPO full SYSVOL tree (including empty dirs) ==="
Get-ChildItem "\\$srv\SYSVOL\$domain\Policies\$leGuid" -Recurse -EA SilentlyContinue | ForEach-Object {
    $rel = $_.FullName.Replace("\\$srv\SYSVOL\$domain\Policies\$leGuid", '')
    $type = if ($_.PSIsContainer) { '[DIR]' } else { "[FILE $(($_.Length))]" }
    Write-Output "  $type $rel"
}
