Import-Module ActiveDirectory
# Kiosk GPO GUID (known)
$guid = '32d76052-4d92-446c-95fb-614653f84742'
# Correct CSE GUIDs for GP Preferences Shortcuts
# CSE: {BC75B1ED-5833-4858-9BB8-CBF0B166DF9D} = GP Preferences engine
# Tool: {0F6B957E-509E-11D1-A7CC-0000F87571E3} = Shortcuts snap-in
$cse = '[{BC75B1ED-5833-4858-9BB8-CBF0B166DF9D}{0F6B957E-509E-11D1-A7CC-0000F87571E3}]'
$dn = "CN={$guid},CN=Policies,CN=System,DC=cascades,DC=local"
Set-ADObject $dn -Replace @{gPCUserExtensionNames=$cse}
$verify = (Get-ADObject $dn -Properties gPCUserExtensionNames).gPCUserExtensionNames
Write-Output "AD gPCUserExtensionNames: $verify"

# Fix GPT.INI too
$gptPath = "\\cascades.local\SYSVOL\cascades.local\Policies\{$guid}\GPT.INI"
$ini = Get-Content $gptPath -Raw
$ini = $ini -replace 'gPCUserExtensionNames=.*', "gPCUserExtensionNames=$cse"
if ($ini -match 'Version=(\d+)') {
    $ver = [int]$matches[1]; $newVer = ((($ver -shr 16)+1) -shl 16) -bor ($ver -band 0xFFFF)
    $ini = $ini -replace "Version=\d+", "Version=$newVer"
}
Set-Content $gptPath $ini -Force
Write-Output "GPT.INI:"
Get-Content $gptPath

# Verify the Shortcuts.xml exists
$xmlPath = "\\cascades.local\SYSVOL\cascades.local\Policies\{$guid}\User\Preferences\Shortcuts\Shortcuts.xml"
Write-Output ""
if (Test-Path $xmlPath) { Write-Output "Shortcuts.xml: EXISTS"; Get-Content $xmlPath -Raw } else { Write-Output "Shortcuts.xml: MISSING" }
