I need a little help making a script that removes all printers, ports and drivers apart from the default microsoft offerings such as fax and print to pdf, and any epson printers as those are for labels and never an issue, for the purpose of fixing any printer related issues and starting as if the computer has just been imaged fresh.
So far I have this:
Get-Printer | Where-Object { $_.Name -notmatch "PDF|txt|fax|usb|enhanced|epson|microsoft" } | Remove-Printer
Get-Printerdriver | Where-Object { $_.Name -notmatch "PDF|txt|fax|usb|enhanced|epson|microsoft" } | remove-printerdriver
Get-Printerport | Where-Object { $_.Name -notmatch "PDF|txt|fax|usb|enhanced|epson|microsoft" } | remove-printerport
I feel there would perhaps be a better way to do this and also add a bit of feedback so the person using the script knows what has been deleted and if anything failed to remove.
Any help or pointing in the right direction would be greatly appreciated.
Write-Host
orWrite-Output
command up top and state, "This list of printers will be removed from this computer" and then run(Get-Printer | Where-Object { $_.Name -notmatch "PDF|txt|fax|usb|enhanced|epson|microsoft" }).Name
, let the remove logic run next, and then run another line that says, "These printers are on your computer" and then run(Get-Printer ).Name
. You basically have everything you need though other than those trivial adjustments. Let me know what you think abou that.