Thursday, April 11, 2013

How to delete printer driver using WMI and powershell

In this case a new network printer was installed on network with ip address w.x.y.z. Unfortunately, this ip address w.x.y.z was belonging to some previously installed network printer that was decommissioned. On network there were client workstations that were using printer driver from the decommissioned printer pointing to w.x.y.z ip address. This situation was causing old spooled documents from clients for the decommissioned printer to print garbage on this new different type of printer with ip address w.x.y.z. The network administrator has provided list of client computers that were trying to empty their spool with old printer driver to the w.x.y.z ip address.
One way to delete this old printer driver pointing to w.x.y.z ip address from clients is using wmi with powershell.
First cancel old print jobs:

PS C:\Temp> (Get-WmiObject win32_printer -computer client1,client2... -filter "Portname = 'IP_w.x.y.z'").cancelalljobs()

Then, delete the print driver :

PS C:\Temp> (Get-WmiObject win32_printer -computer client1,client2... -filter "Portname = 'IP_w.x.y.z'").delete()
 

No comments:

Post a Comment