Forum Discussion
David42fr
Jun 18, 2025Copper Contributor
Uninstalling printer queues
Hello,
We are going to migrate from shared printers on a server to a new system.
We need to delete all the printer queues which are \\server\printer01/02/03....
I tried using remediation script with no luck.
Here is the detection part :
# Recherche des imprimantes correspondant aux motifs IM?? ou CANON_*
$printers = Get-Printer | Where-Object {
$_.Name -like '\\server\IM*' -or $_.Name -like '\\server\CANON_*'
}
if ($printers) {
#Write-Output "Imprimantes détectées :"
#$printers | ForEach-Object { Write-Output $_.Name }
exit 1 # Code de sortie 1 = imprimantes trouvées
} else {
#Write-Output "Aucune imprimante correspondante trouvée."
exit 0 # Code de sortie 0 = aucune imprimante trouvée
}
and here is the remediation part :
# Supprimer les imprimantes contenant "IM" ou commençant par "CANON_"
$printersToRemove = Get-Printer | Where-Object {
$_.Name -like '\\server\IM*' -or $_.Name -like '\\server\CANON_*'
}
foreach ($printer in $printersToRemove) {
try {
Remove-Printer -Name $printer.Name -ErrorAction Stop
# Write-Output "Imprimante supprimée : $($printer.Name)"
} catch {
Write-Output "Erreur lors de la suppression de : $($printer.Name) - $_"
}
}
And the settings :
SettingsDetection script YesRemediation script YesRun this script using the logged-on credentials YesEnforce script signature check NoRun script in 64-bit PowerShell No
If I test the scripts locally, it works.
Any ideas?
Thanks
1 Reply
- Moritz45Copper Contributor
Hello. Can you add more details? Did you run the remediation script in user or system context? Do you receive an error when running it as a remediation? You can expand the columns to display the actual error thrown. We can investigate this further once you share this information :)