Deleting a services with Get-CIM*

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Daniel Daniel 3 years, 1 month ago.

  • Author
    Posts
  • #13356
    Profile photo of Daniel
    Daniel
    Participant

    Hello everyone

    I'm reworking some of my cmdlets to use Get-Cim instead of Get-WMIobject. My issue is

    The Get-WmiObject way works.

    $TDOCservices = Get-WmiObject -Class win32_service -filter "Name LIKE '%TDOC%'"
    $TDOCservices.delete()

    The Get-CimInstance way is not working...

    $TDOCservices = Get-CimInstance -ClassName win32_service -Filter "Name LIKE '%TDOC%'"
    $TDOCservices.delete()

    Can any tell me what I'm overlooking or misunderstood?

  • #13357
    Profile photo of Richard Siddaway
    Richard Siddaway
    Participant

    Get-CimInstance returns an inert object that doesn't have the WMI class methods available
    You will need to run as
    Get-CimInstance -ClassName win32_service -Filter “Name LIKE '%TDOC%'” | invoke-cimmethod -methodname Delete

    Remember that CIM cmdlets use WSMAN by default to access remote machines

    • #13361
      Profile photo of Daniel
      Daniel
      Participant

      Thanks Richard
      Will read up on the Invoke-cimmethod 🙂

You must be logged in to reply to this topic.