Welcome › Forums › General PowerShell Q&A › Delete Method for Win32_printer does not completely remove a local printer
This topic contains 6 replies, has 4 voices, and was last updated by
-
AuthorPosts
-
October 20, 2014 at 8:54 am #19859
I have been working on a script to remove a locally added network IP Printer – that was originally added using the print wizard with plug and play drivers not hosted on a print server – from a few machines in my area at work. The problem that I have ran into is that whenever I query the correct printer using the following command the "delete" method removes the record from WMI, but the printer info remains in the "Devices and Printers" GUI even though you cannot print to it.
(Get-WmiObject -class win32_printer | where-object {$_.Name -eq "PRINTER (HP LaserJet 500 color M551)"} ).delete()
I initially thought that I was possibly forgetting to remove the win32_tcpipprinterport, but it does not use a tcpip port. I also thought that it might even have an authentication issue as the UAC is prompted when the printer is removed manually, but I could not find anything on this by searching the web. I would appreciate any insight on what may be going on. I also included a print out below of the cmdlet above excluding the delete method.
PSComputerName : TestComputer Status : Unknown Name : PRINTER (HP LaserJet 500 color M551) __GENUS : 2 __CLASS : Win32_Printer __SUPERCLASS : CIM_Printer __DYNASTY : CIM_ManagedSystemElement __RELPATH : Win32_Printer.DeviceID="PRINTER (HP LaserJet 500 color M551)" __PROPERTY_COUNT : 86 __DERIVATION : {CIM_Printer, CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement} __SERVER : TestComputer __NAMESPACE : root\cimv2 __PATH : \\TestComputer\root\cimv2:Win32_Printer.DeviceID="PRINTER (HP LaserJet 500 color M551)" Attributes : 576 Availability : AvailableJobSheets : AveragePagesPerMinute : 0 Capabilities : {4, 2, 3, 5} CapabilityDescriptions : {Copies, Color, Duplex, Collate} Caption : PRINTER (HP LaserJet 500 color M551) CharSetsSupported : Comment : ConfigManagerErrorCode : ConfigManagerUserConfig : CreationClassName : Win32_Printer CurrentCapabilities : CurrentCharSet : CurrentLanguage : CurrentMimeType : CurrentNaturalLanguage : CurrentPaperType : Default : False DefaultCapabilities : DefaultCopies : DefaultLanguage : DefaultMimeType : DefaultNumberUp : DefaultPaperType : DefaultPriority : 0 Description : DetectedErrorState : 0 DeviceID : PRINTER (HP LaserJet 500 color M551) Direct : False DoCompleteFirst : True DriverName : HP LaserJet 500 color M551 PCL6 EnableBIDI : False EnableDevQueryPrint : False ErrorCleared : ErrorDescription : ErrorInformation : ExtendedDetectedErrorState : 0 ExtendedPrinterStatus : 2 Hidden : False HorizontalResolution : 600 InstallDate : JobCountSinceLastReset : 0 KeepPrintedJobs : False LanguagesSupported : {50} LastErrorCode : Local : True Location : MarkingTechnology : MaxCopies : MaxNumberUp : MaxSizeSupported : MimeTypesSupported : NaturalLanguagesSupported : Network : False PaperSizesSupported : {7, 8, 1, 1...} PaperTypesAvailable : Parameters : PNPDeviceID : PortName : WSD-af3c56c0-8fef-4253-9512-fd17a59f565f.0067 PowerManagementCapabilities : PowerManagementSupported : PrinterPaperNames : {Letter, Legal, Statement, Executive...} PrinterState : 0 PrinterStatus : 3 PrintJobDataType : RAW PrintProcessor : hpcpp145 Priority : 1 Published : False Queued : False RawOnly : False SeparatorFile : ServerName : Shared : False ShareName : SpoolEnabled : True StartTime : StatusInfo : SystemCreationClassName : Win32_ComputerSystem SystemName : TestComputer TimeOfLastReset : UntilTime : VerticalResolution : 600 WorkOffline : False Scope : System.Management.ManagementScope Path : \\TestComputer\root\cimv2:Win32_Printer.DeviceID="PRINTER (HP LaserJet 500 color M551)" Options : System.Management.ObjectGetOptions ClassPath : \\TestComputer\root\cimv2:Win32_Printer Properties : {Attributes, Availability, AvailableJobSheets, AveragePagesPerMinute...} SystemProperties : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...} Qualifiers : {dynamic} Site : Container :
-
October 20, 2014 at 9:42 am #19864
I haven't been able to reproduce this problem so far. What operating system are you using?
-
October 20, 2014 at 9:52 am #19866
What error does it give you?
-
October 20, 2014 at 12:09 pm #19876
I am running the script on Windows 7 SP1 with PowerShell v. 4. There are no error codes generated.
The delete method successfully runs and removes the printer from the Win32_Printer section; however, the device information (i.e. IP address, Manufacture ID, etc) and the WSD port still remain under Control Panel > Hardware and Sound > Devices and Printers. (Even though it cannot be used and there is no information under Win32_Printer).
I did find more information for the device under CIM_LogicalDevice (Below) after I removed the printer using the method above, so I know that there are still remnants of this printer somewhere on the computer. I am just not sure how to remove the residual information so that the printer will not be displayed in Devices and Printers for users and if it may be edited/removed via WMI or CIM.
Caption : PRINTER (HP LaserJet 500 color M551) Description : UMBus Enumerator InstallDate : Name : PRINTER (HP LaserJet 500 color M551) Status : OK Availability : ConfigManagerErrorCode : 0 ConfigManagerUserConfig : False CreationClassName : Win32_PnPEntity DeviceID : IPBUSENUMROOT\UMB\2&BA1FFA4&0&URN:UUID:1B2 F2F6B-1954-3753-44C8-3CD92B9FA120 ErrorCleared : ErrorDescription : LastErrorCode : PNPDeviceID : IPBUSENUMROOT\UMB\2&BA1FFA4&0&URN:UUID:1B2 F2F6B-1954-3753-44C8-3CD92B9FA120 PowerManagementCapabilities : PowerManagementSupported : StatusInfo : SystemCreationClassName : Win32_ComputerSystem SystemName : TestComputer ClassGuid : {4d36e97d-e325-11ce-bfc1-08002be10318} CompatibleID : HardwareID : {UMB\UMBUS} Manufacturer : HP Service : umbus PSComputerName :
-
October 20, 2014 at 10:37 pm #19888
IMHO it's problem with driver. Try to replace driver with some other driver for a test purpose and run it again.
-
-
October 21, 2014 at 5:33 am #19911
You can try using the WScript.Network method. I've used WMI to enumerate the printers and WScript.Network to Add\Remove the printers in the past and it's worked well.
$wshNetwork = New-Object -ComObject WScript.Network $wshNetwork.RemovePrinterConnection("\\prntsvr01\myprinter")
-
October 21, 2014 at 7:30 am #19918
Ondrej, I agree that it may be an issue with the driver. I have added the same printer via script with a device specific driver instead of the Plug-N-Play driver, which was installed when the printer was installed manually, and that device may be completely removed by running the query first mentioned. Unfortunately changing the driver in testing is not going to do me any good on removing it from the computers in production.
Also the issue may be related to the fact that the network printer is installed locally through the original PNP. (Sorry Rob I don't think your script will work on this one, but thanks for the suggestion). I found information for the device under "Win32_PnpEntity." with more information about the UMB Connection. Unfortunately I do not think there is a way to remove the device from this area of WMI. I think this may be the area that is causing it to hang around in "Devices and Printers."
-
AuthorPosts
The topic ‘Delete Method for Win32_printer does not completely remove a local printer’ is closed to new replies.