Import-Module GroupPolicy
# Move GPP shortcuts from CSC - Caregiver Workstation to CSC - Nurse Station Kiosk
$kioskGuid = (Get-GPO -Name 'CSC - Nurse Station Kiosk').Id
$cwGuid = '3B5CD9A6-A278-4676-A9FD-9396D21A8261'
# Read current shortcuts XML from Caregiver Workstation GPO
$srcDir = "\\cascades.local\SYSVOL\cascades.local\Policies\{$cwGuid}\User\Preferences\Shortcuts"
$srcXml = "$srcDir\Shortcuts.xml"
$content = Get-Content $srcXml -Raw -ErrorAction SilentlyContinue
Write-Output "Source XML exists: $($null -ne $content)"
# Write to Nurse Station Kiosk GPO
$dstDir = "\\cascades.local\SYSVOL\cascades.local\Policies\{$kioskGuid}\User\Preferences\Shortcuts"
New-Item -ItemType Directory -Path $dstDir -Force | Out-Null
Set-Content "$dstDir\Shortcuts.xml" $content -Encoding UTF8 -Force
Write-Output "Copied shortcuts to kiosk GPO"
# Remove from Caregiver Workstation GPO
Remove-Item $srcXml -Force
Write-Output "Removed from Caregiver Workstation GPO"
# Set CSE GUIDs on kiosk GPO AD object
$cse = '[{42B5FAAE-6536-11D2-AE5A-0000F87571E3}{0F6B957D-509E-11D1-A7CC-0000F87571E3}]'
$dn = "CN={$kioskGuid},CN=Policies,CN=System,DC=cascades,DC=local"
$existing = (Get-ADObject $dn -Properties gPCUserExtensionNames).gPCUserExtensionNames
if ($existing) { $merged = $existing + $cse } else { $merged = $cse }
Set-ADObject $dn -Replace @{gPCUserExtensionNames=$merged}
Write-Output "CSE GUIDs set on kiosk GPO"
# Bump kiosk GPO version
$gptPath = "\\cascades.local\SYSVOL\cascades.local\Policies\{$kioskGuid}\GPT.INI"
$ini = Get-Content $gptPath -Raw
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"
    # Add CSE to GPT.INI too
    if ($ini -notmatch 'gPCUserExtensionNames') { $ini = $ini.TrimEnd() + "`r`ngPCUserExtensionNames=$cse`r`n" }
    Set-Content $gptPath $ini -Force
    Write-Output "Kiosk GPO version bumped: $ver -> $newVer"
}
Write-Output (Get-Content $gptPath -Raw)
