Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Get-WmiObject and starting/stopping remote services

Reply
 
Old 07-12-2006   #1 (permalink)
Sourabh


 
 

Get-WmiObject and starting/stopping remote services

I am trying to connect remotely to a server, using credentials that are
different than my current credentials, and then start / stop a particular
services. For that I am using the Get-WmiObject but am not finding a Start
or Stop method.

$a = Get-WmiObject Win32_service -computer Test01 -Credential
Test01\administrator | Where-Object { $_.Name -match "^Cms*" }
$a | Get-Member

What am I missing here? Is this the best to accomplish remotely start stop
services, using different credentials or is there a better way ?

TIA
-Sourabh



My System SpecsSystem Spec
Old 07-12-2006   #2 (permalink)
Wei Wu [MSFT]


 
 

Re: Get-WmiObject and starting/stopping remote services

For now , you can do something like
PS C:\> $a = gwmi win32_service -filter "name='spooler'"
PS C:\> $a.invokemethod("stopservice",$null)
3

In our next release, you will be able to do
$a.stopservice()

You can read more about it at
http://blogs.msdn.com/powershell/arc...26/647038.aspx


--
Wei Wu [MSFT]
Windows PowerShell Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Sourabh" <kksmkksm@yahoo.com> wrote in message
news:O495$kWpGHA.3288@TK2MSFTNGP03.phx.gbl...
>I am trying to connect remotely to a server, using credentials that are
>different than my current credentials, and then start / stop a particular
>services. For that I am using the Get-WmiObject but am not finding a Start
>or Stop method.
>
> $a = Get-WmiObject Win32_service -computer Test01 -Credential
> Test01\administrator | Where-Object { $_.Name -match "^Cms*" }
> $a | Get-Member
>
> What am I missing here? Is this the best to accomplish remotely start stop
> services, using different credentials or is there a better way ?
>
> TIA
> -Sourabh
>
>



My System SpecsSystem Spec
Old 07-12-2006   #3 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Get-WmiObject and starting/stopping remote services

For now, you can also try this:
$svc = Get-WmiObject -Class Win32_Service -ComputerName . |
?{$_.Name -eq "UPHClean"}
$svc.InvokeMethod("StopService", $null)

The key issue here that they are addressing is that WMI methods aren't
exposed by standard .NET wrappers in a clean fashion. Notice that instead of
having a named method, in RC1 we have to call a generic InvokeMethod method
that takes two arguments. The first argument is the method name, and the
second argument is actually an ARRAY of the parameters that the WMI method
takes. Since StopService takes no parameters, $null works ok.

Info on the Win32_Service class can be found here online:

http://msdn.microsoft.com/library/en...32_service.asp

A more general way to find methods for all WMI classes in root/cimv2 on a
specific machine is to use the following command:

Get-WmiObject -List -ComputerName . | %{$_.PSBase} |
Select-Object -ExpandProperty Methods




"Sourabh" <kksmkksm@yahoo.com> wrote in message
news:O495$kWpGHA.3288@TK2MSFTNGP03.phx.gbl...
>I am trying to connect remotely to a server, using credentials that are
>different than my current credentials, and then start / stop a particular
>services. For that I am using the Get-WmiObject but am not finding a Start
>or Stop method.
>
> $a = Get-WmiObject Win32_service -computer Test01 -Credential
> Test01\administrator | Where-Object { $_.Name -match "^Cms*" }
> $a | Get-Member
>
> What am I missing here? Is this the best to accomplish remotely start stop
> services, using different credentials or is there a better way ?
>
> TIA
> -Sourabh
>
>



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Self starting and stopping torrent software Software
Starting & stopping services VB Script
How to make a batch file on starting and stopping services from command prompt ? General Discussion
stopping and starting service PowerShell
stopping a program from starting up Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46