locked
Why Get-CimInstance do not have (GM) member called startservice, stopservice RRS feed

  • Question

  • HI ,

    can anyone tell me why (Get-CimInstance -ClassName win32_service)|get-member do not have method called startservice and stopservice? where (Get-WmiObject -Class win32_service)|Get-member have startservice and stopservice.

    As Microsoft is not developing wmiobject anymore is it not feasible to include these method in CimInstance also????




    Saturday, April 11, 2020 5:47 AM

Answers

  • This is a more challenging topic.  You could say the cim commands are less user friendly than the wmi commands when it comes to methods.  You need to use get-cimclass to list the methods.  Both types of commands are using the same wmi database on the backend.


    get-cimclass win32_service | % cimclassmethods

    And then invoke-cimmethod to invoke a method.  At least the -name parameter supports tab completion.  You can't leave out '-name'.  A returnvalue of 0 is success.


    get-ciminstance win32_service | where name -eq spooler |
      Invoke-CimMethod -name stopservice

    ReturnValue PSComputerName
    ----------- --------------
              0


    Reference:  Hey dude where are my methods?  https://devblogs.microsoft.com/scripting/hey-dude-where-are-my-methods/

    • Edited by JS2010 Saturday, April 11, 2020 6:52 PM
    • Marked as answer by Ankit_Jaiswal Saturday, April 11, 2020 8:24 PM
    Saturday, April 11, 2020 2:29 PM

All replies

  • You people new to PowerShell and windows technology need to learn to use help before asking questions.

     help get-ciminstance -full


    \_(ツ)_/

    Saturday, April 11, 2020 6:30 AM
  • This is a more challenging topic.  You could say the cim commands are less user friendly than the wmi commands when it comes to methods.  You need to use get-cimclass to list the methods.  Both types of commands are using the same wmi database on the backend.


    get-cimclass win32_service | % cimclassmethods

    And then invoke-cimmethod to invoke a method.  At least the -name parameter supports tab completion.  You can't leave out '-name'.  A returnvalue of 0 is success.


    get-ciminstance win32_service | where name -eq spooler |
      Invoke-CimMethod -name stopservice

    ReturnValue PSComputerName
    ----------- --------------
              0


    Reference:  Hey dude where are my methods?  https://devblogs.microsoft.com/scripting/hey-dude-where-are-my-methods/

    • Edited by JS2010 Saturday, April 11, 2020 6:52 PM
    • Marked as answer by Ankit_Jaiswal Saturday, April 11, 2020 8:24 PM
    Saturday, April 11, 2020 2:29 PM