Author Posts

May 5, 2016 at 8:01 am

What happened to the delete method on the Win32_Printer class? While it still appears to be present on the older Windows 7 machines we have, there is no trace of it on my Win10 machine. I know they introduced new cmdlets for dealing with printers, but it still strikes me as odd that this method is missing.

May 5, 2016 at 10:22 am

I can confirm its not present on Windows 10 Insider Preview build 14332

You can always do
Get-CimInstance -ClassName Win32_Printer -Filter "" | Remove-CimInstance

The printer cmdlets use a different CIM class:
ROOT/StandardCimv2/MSFT_Printer

May 5, 2016 at 10:40 am

this worked for me

gwmi win32_printer -Filter "name = 'Adobe PDF (Copy 1)'" | % {$_.delete()}

or this for a local printer

Invoke-WmiMethod -Class win32_process -Name create -ArgumentList "rundll32 printui.dll, PrintUIEntry /dl /nDeleteMe" -ComputerName $env:COMPUTERNAME

or this for a network printer

Invoke-WmiMethod -Class win32_process -Name create -ArgumentList "rundll32 printui.dll, PrintUIEntry /gd /n\\Server\DeleteMe" -ComputerName $env:COMPUTERNAME

also, this for a network printer

(New-Object -ComObject WScript.Network).RemovePrinterConnection('\\server\printer')

May 6, 2016 at 4:28 am

The delete method isn't part of the WMI class – see the definition here:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx

The delete method is from System.Management.ManagementObject which is the .NET class used to work with WMI objects using the WMI cmdlets.
https://msdn.microsoft.com/en-us/library/system.management.managementobject_methods(v=vs.110).aspx

The Delete method is masked in the normal object

$printers = Get-WmiObject -Class Win32_Printer
$printers[0] | Get-Member -MemberType Method | select name

Name
—-
CancelAllJobs
GetSecurityDescriptor
Pause
PrintTestPage
RenamePrinter
Reset
Resume
SetDefaultPrinter
SetPowerState
SetSecurityDescriptor

You have to look at the base object
$printers[0] | Get-Member -MemberType Method -View Base | select name

Name
—-
Clone
CompareTo
CopyTo
CreateObjRef
Delete
Dispose
Equals
Get
GetHashCode
GetLifetimeService
GetMethodParameters
GetObjectData
GetPropertyQualifierValue
GetPropertyValue
GetQualifierValue
GetRelated
GetRelationships
GetText
GetType
InitializeLifetimeService
InvokeMethod
Put
SetPropertyQualifierValue
SetPropertyValue
SetQualifierValue
ToString

If you use the CIM cmdlets

$printers = Get-CimInstance -ClassName Win32_printer
PS> $printers[0] | Get-Member -MemberType Method -View Base | select name

Name
—-
Clone
Dispose
Equals
GetCimSessionComputerName
GetCimSessionInstanceId
GetHashCode
GetObjectData
GetType
ToString

You won't see a Delete method. They use Microsoft.Management.Infrastructure.CimInstance. which doesn't have a delete method
https://msdn.microsoft.com/en-us/library/microsoft.management.infrastructure.ciminstance_methods(v=vs.85).aspx