This commit is contained in:
2024-08-09 18:42:44 +02:00
commit a560094e34
5 changed files with 123 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
#Read printers.csv as input
$Printers = Import-Csv .\printers.csv
#Loop through all printers in the csv-file and remove the printers listed
foreach ($printer in $Printers) {
#Set options
$PrinterRemoveOptions = @{
Confirm = $false
Name = $printer.Name
}
$PrinterPortRemoveOptions = @{
Confirm = $false
Computername = $env:COMPUTERNAME
Name = $printer.Name
}
#Remove printers and their ports
Get-WmiObject -Class Win32_Printer | Where-Object { $_.Name -eq $printer.Name } | ForEach-Object { $_.Delete() }
Start-Sleep -Seconds 10
Get-WmiObject -Class Win32_TCPIPPrinterPort | Where-Object { $_.Name -eq $printer.Name } | ForEach-Object { $_.Delete() }
}
#Remove drivers from the system
foreach ($driver in $Printers.drivername | Select-Object -Unique) {
$PrinterDriverRemoveOptions = @{
Confirm = $false
Computername = $env:COMPUTERNAME
Name = $driver
RemoveFromDriverStore = $true
}
Remove-PrinterDriver @PrinterDriverRemoveOptions
}