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

# Find the LE folder redirection GPO
$gpo = Get-GPO -Name 'CSC - Folder Redirection (LE)' -Domain $domain
Write-Output "GPO: $($gpo.DisplayName)"
Write-Output "GUID: {$($gpo.Id.ToString().ToUpper())}"
$gpoPath = "$sysvol\{$($gpo.Id.ToString().ToUpper())}"
Write-Output "Path: $gpoPath"
Write-Output ""

# List all files in the GPO folder recursively
Write-Output "=== SYSVOL file tree ==="
Get-ChildItem $gpoPath -Recurse -File -EA SilentlyContinue | ForEach-Object {
    Write-Output "  $($_.FullName.Replace($gpoPath, ''))"
}
Write-Output ""

# Show GPT.INI
Write-Output "=== GPT.INI ==="
[System.IO.File]::ReadAllText("$gpoPath\GPT.INI") | Write-Output
Write-Output ""

# Show any fdeploy.ini or redirection files
$fdeployPath = "$gpoPath\User\Documents & Settings"
if (Test-Path $fdeployPath) {
    Write-Output "=== fdeploy.ini ==="
    [System.IO.File]::ReadAllText("$fdeployPath\fdeploy.ini") | Write-Output
} else {
    Write-Output "No 'Documents & Settings' folder found"
}

# Also check the unlinked CSC - Folder Redirection GPO
Write-Output ""
Write-Output "=== CSC - Folder Redirection (unlinked) ==="
$gpo2 = Get-GPO -Name 'CSC - Folder Redirection' -Domain $domain -EA SilentlyContinue
if ($gpo2) {
    Write-Output "GUID: {$($gpo2.Id.ToString().ToUpper())}"
    $gpo2Path = "$sysvol\{$($gpo2.Id.ToString().ToUpper())}"
    Get-ChildItem $gpo2Path -Recurse -File -EA SilentlyContinue | ForEach-Object {
        Write-Output "  $($_.FullName.Replace($gpo2Path, ''))"
    }
    $fd2 = "$gpo2Path\User\Documents & Settings\fdeploy.ini"
    if (Test-Path $fd2) {
        Write-Output "fdeploy.ini:"
        [System.IO.File]::ReadAllText($fd2) | Write-Output
    }
} else {
    Write-Output "GPO not found"
}
