Win32_Printer delete method

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 4 months, 3 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38641
    Profile photo of Stefan Werner
    Stefan Werner
    Participant

    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.

    #38645

    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

    #38648
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    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')
    
    #38675

    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

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.