locked
use win32_service on remote machines RRS feed

  • Question

  • I've seen this script on the web, but is doesn't work for me:

    (gwmi win32_service -computername Workstation -filter "name='telnet'").InvokeMethod("StopService",$null)

    I get: "You cannot call a method on a null-valued expression"

     

    This machine isn't shared, but I was able to use Win32_OperatingSystem to log off a remote non-shared machine. Why I can't I use win32_service to do stuff like that?

    Thursday, March 25, 2010 4:02 PM

Answers

  • You should look through the documentation on connecting to WMI on a remote computer:

    http://msdn.microsoft.com/en-us/library/aa389290(VS.85).aspx

    An alternative would be to enable winrm, and perform your wmi calls on the remote computer with invoke-command if you do not want to open up wmi on your firewall... of course that means you'll need to open up the ports for winrm, however.  With the winrm method you open up a lot more power than just WMI.  Nearly all commands can be executed remotely as if you were calling them locally with this method.

     

    • Marked as answer by Mervyn Zhang Monday, March 29, 2010 8:51 AM
    Thursday, March 25, 2010 4:49 PM
  • Oh! Oh ____ I forgot its "tlnsvr"... hehe sorry...
    • Marked as answer by red888 Thursday, March 25, 2010 4:36 PM
    Thursday, March 25, 2010 4:34 PM

All replies

  • The error message seems to indicate that the initial gwmi didn't return anything.

    If you run just the wmi query on the service, do you get a return?

    gwmi win32_service -computername Workstation -filter "name='telnet'"

     

    Thursday, March 25, 2010 4:09 PM
  • It runs without error. But thats all it does.
    Thursday, March 25, 2010 4:27 PM
  • means that telnet service isn't there..How about get-Service -name "telnet"?
    Ravikanth
    http://www.ravichaganti.com/blog
    Twitter: @ravikanth
    Thursday, March 25, 2010 4:32 PM
  • I get the error too.  It's because I have no service named "telnet" running.  Try it with something else and it should work, or make sure you have a process named telnet running.

    As an alternative you can do the following with the native cmdlets to do the same thing:

    (get-process -ComputerName Workstation "telnet").kill()

    You can get the list of process running with:

    get-process

     

    Thursday, March 25, 2010 4:33 PM
  • I have the "remote" computer on my desk. Rest assured telnet is installed and functional on this PC.
    Thursday, March 25, 2010 4:33 PM
  • Oh! Oh ____ I forgot its "tlnsvr"... hehe sorry...
    • Marked as answer by red888 Thursday, March 25, 2010 4:36 PM
    Thursday, March 25, 2010 4:34 PM
  • It sounds like it ran the query, and came up empty.  Are you sure that service name is right, and is installed on the workstation?
    Thursday, March 25, 2010 4:35 PM
  • Wow I feel like an ____ sorry about that. Another question though about WMI.

     

    What services or whatever else is necessary to be running on a remote, non-shared, computer for me to use all the methods of wmi classes against it?

    Thursday, March 25, 2010 4:38 PM
  • You should look through the documentation on connecting to WMI on a remote computer:

    http://msdn.microsoft.com/en-us/library/aa389290(VS.85).aspx

    An alternative would be to enable winrm, and perform your wmi calls on the remote computer with invoke-command if you do not want to open up wmi on your firewall... of course that means you'll need to open up the ports for winrm, however.  With the winrm method you open up a lot more power than just WMI.  Nearly all commands can be executed remotely as if you were calling them locally with this method.

     

    • Marked as answer by Mervyn Zhang Monday, March 29, 2010 8:51 AM
    Thursday, March 25, 2010 4:49 PM
  • I have a mixed environment with 2000 machines which we won't be installing any new software or updates on so I thought WMI would be perfect to do some remote management with.

    Just curious, why don't I hear more about remote management with WMI? I use to think you could only use it to get info, but the fact you can push out some settings too is really cool- especially cause the PCs don't need to be shared.
    Thursday, March 25, 2010 5:29 PM
  • WMI has a reputation for being a bit kludgy.  It's great in small doses, and is very powerful, but it's not always the right tool for the job.  There may be some that disagree with that, but I generally look for a native method first.  Especially now that winrm is available, but sometimes it just makes sense to use WMI.  

    There are plenty of monitoring systems that consume WMI data from systems.  

    Being able to consume wmi events is also really cool and powerful.

    Thursday, March 25, 2010 9:02 PM