Compare commits
2 Commits
a1de519eee
...
7b121a4f2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b121a4f2f | ||
|
|
80a46f75d0 |
@@ -6,7 +6,7 @@ if (!(Test-Path $flagFolder)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Test-Path $flagFile) {
|
if (Test-Path $flagFile) {
|
||||||
Write-Host "Script has already run. Exiting."
|
Write-Host "Script has already run. Exiting." --ForegroundColor Red
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,11 +26,13 @@ $HKLMPrinterPaths = @(
|
|||||||
'HKEY_LOCAL_MACHINE\SOFTWARE\Xerox\PrinterDriver'
|
'HKEY_LOCAL_MACHINE\SOFTWARE\Xerox\PrinterDriver'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Write-Host "Stopping spooler" --ForegroundColor Yellow
|
||||||
net stop spooler
|
net stop spooler
|
||||||
|
|
||||||
foreach ($printerPath in $HKLMPrinterPaths) {
|
foreach ($HKLMPrinterPaths in $HKLMPrinterPaths) {
|
||||||
try {
|
try {
|
||||||
Remove-Item -Path "Registry::$printerPath" -Recurse -Force -ErrorAction Stop
|
Remove-Item -Path "Registry::${HKLMPrinterPaths}" -Recurse -Force -ErrorAction Stop
|
||||||
|
Write-Host "Removed local machine key ${HKLMPrinterPaths}" --ForegroundColor Green
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Error: $($_.Exception.Message)"
|
Write-Host "Error: $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
@@ -40,24 +42,43 @@ foreach ($sidKey in $sids) {
|
|||||||
$sid = $sidKey.PSChildName
|
$sid = $sidKey.PSChildName
|
||||||
$profilePath = (Get-ItemProperty -Path $sidKey.PSPath -Name ProfileImagePath).ProfileImagePath
|
$profilePath = (Get-ItemProperty -Path $sidKey.PSPath -Name ProfileImagePath).ProfileImagePath
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($printerPath in $printerPaths) {
|
foreach ($printerPath in $printerPaths) {
|
||||||
try {
|
try {
|
||||||
Remove-Item -Path "Registry::HKEY_USERS\$sid$printerPath" -Recurse -Force -ErrorAction Stop
|
Remove-Item -Path "Registry::HKEY_USERS\${sid}${printerPath}" -Recurse -Force -ErrorAction Stop
|
||||||
|
Write-Host "Removed user profile key HKEY_USERS\${sid}${printerPath}" --ForegroundColor Green
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Error: $($_.Exception.Message)"
|
Write-Host "Error: $($_.Exception.Message)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (-not $mounted) {
|
|
||||||
$unloadResult = & reg.exe unload "HKU\$sid" 2>&1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Remove-Item -Path "C:\Windows\System32\spool\PRINTERS" -Recurse -Force
|
||||||
|
Write-Host "Removed PRINTERS from spooler" --ForegroundColor Green
|
||||||
|
} catch {
|
||||||
|
Write-Host "Error Removing PRINTERS from spooler" --ForegroundColor Red
|
||||||
|
Write-Host "Error: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Remove-Item -Path "C:\Windows\System32\spool\V4Dirs" -Recurse -Force
|
||||||
|
Write-Host "Removed V4Dirs from spooler" --ForegroundColor Green
|
||||||
|
} catch {
|
||||||
|
Write-Host "Error Removing V4Dirs from spooler" --ForegroundColor Red
|
||||||
|
Write-Host "Error: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Starting spooler" --ForegroundColor Yellow
|
||||||
net start spooler
|
net start spooler
|
||||||
|
|
||||||
|
|
||||||
|
Write-Host "Running gpupdate" --ForegroundColor Yellow
|
||||||
gpupdate /force
|
gpupdate /force
|
||||||
|
|
||||||
|
try {
|
||||||
New-Item -Path $flagFile -ItemType File -Force
|
New-Item -Path $flagFile -ItemType File -Force
|
||||||
|
Write-Host "created flag at ${flagFile}" --ForegroundColor Green
|
||||||
|
} catch {
|
||||||
|
Write-Host "Could not create flag at ${flagFile}" --ForegroundColor Red
|
||||||
|
Write-Host "Error: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user