51 lines
1.9 KiB
PowerShell
51 lines
1.9 KiB
PowerShell
Import-Module GroupPolicy
|
|
# Identify which GPO this is
|
|
$gpo = Get-GPO -Guid '3B5CD9A6-A278-4676-A9FD-9396D21A8261'
|
|
Write-Output "GPO: $($gpo.DisplayName) (ID: $($gpo.Id))"
|
|
Write-Output "Status: $($gpo.GpoStatus)"
|
|
|
|
# Remove the GPP Shortcuts.xml (stops it recreating shortcuts on login)
|
|
$path = "\\cascades.local\SYSVOL\cascades.local\Policies\{3B5CD9A6-A278-4676-A9FD-9396D21A8261}\User\Preferences\Shortcuts\Shortcuts.xml"
|
|
if (Test-Path $path) {
|
|
Remove-Item $path -Force
|
|
Write-Output "REMOVED: $path"
|
|
# Clean up empty dir
|
|
$dir = Split-Path $path
|
|
if ((Get-ChildItem $dir -ErrorAction SilentlyContinue).Count -eq 0) {
|
|
Remove-Item $dir -Force
|
|
Write-Output "Cleaned empty Shortcuts dir"
|
|
}
|
|
} else {
|
|
Write-Output "Already removed"
|
|
}
|
|
|
|
# Bump GPO version so clients pick up the change
|
|
# Read current version, increment user version
|
|
$gpoPath = "\\cascades.local\SYSVOL\cascades.local\Policies\{3B5CD9A6-A278-4676-A9FD-9396D21A8261}\GPT.INI"
|
|
$ini = Get-Content $gpoPath -Raw
|
|
Write-Output ""
|
|
Write-Output "GPT.INI before:"
|
|
Write-Output $ini
|
|
# Parse version: low 16 bits = computer, high 16 bits = user
|
|
if ($ini -match 'Version=(\d+)') {
|
|
$ver = [int]$matches[1]
|
|
$userVer = ($ver -shr 16) + 1
|
|
$compVer = $ver -band 0xFFFF
|
|
$newVer = ($userVer -shl 16) -bor $compVer
|
|
$ini = $ini -replace "Version=\d+", "Version=$newVer"
|
|
Set-Content $gpoPath $ini -Force
|
|
Write-Output "GPT.INI after (version $ver -> $newVer):"
|
|
Write-Output $ini
|
|
}
|
|
|
|
# Also clean the per-user desktop shortcuts one more time
|
|
Get-ChildItem "C:\Users" -Directory | Where-Object { $_.Name -notin 'Public','Default','Default User','All Users' } | ForEach-Object {
|
|
$desk = Join-Path $_.FullName "Desktop"
|
|
foreach ($f in 'ALIS.url','Helpany.url','PharmCare.url','LinkRx.url') {
|
|
$p = Join-Path $desk $f
|
|
if (Test-Path $p) { Remove-Item $p -Force }
|
|
}
|
|
}
|
|
Write-Output ""
|
|
Write-Output "Cleaned per-user desktop shortcuts"
|