auto
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user