Powershell stop-service error: cannot find any service with service name


I'm working on a script to deploy vendor software to a large environment. The first step is to stop the services in question. The script executes fine in our test environment, but I'm not an admin in the production environment so I'm convinced it's a permissions issue. I can't get admin rights to the prod environment so I need to try to find out anything that I may need to set to grant permissions to stop services remotely. I'm issuing the following command to stop services:

Stop-Service -InputObject $(Get-Service -Computer $destination.Server -Name ("moca."+$destEnv))

When I run the script I get:

Cannot find any service with service name 'moca.WMSPRD'.
+ CategoryInfo          : ObjectNotFound: (moca.WMSPRD:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
+ CategoryInfo          : InvalidData: (:) [Stop-Service], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.StopServiceCommand

The service definitely exists and if I rdp into the target box and issue the stop-service command locally it will execute. So there is something preventing me from stopping the service remotely. Any ideas?

Edit: A coworker suggested using WMI so tried replacing the Stop-Service line with:

(Get-WmiObject -computer $destination.Server Win32_Service -Filter ("Name='moca."+$destEnv+"'")).InvokeMethod("StopService",$null)

and I get:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
+ CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
asked on Stack Overflow Oct 16, 2012 by Justin Holbrook • edited Oct 16, 2012 by Justin Holbrook

2 Answers


If you know the exact service name you can try this

(Get-WmiObject -computerName $_.name Win32_Service -Filter "Name='moca'").StopService()

Here im assuming that the service name is moca

answered on Stack Overflow Nov 12, 2012 by PowerShell

Is DCOM working on the remote computer? I know how to do it with remote powershell, which uses wsman:

 invoke-command comp001 { stop-service adobearmservice }
answered on Stack Overflow Sep 15, 2019 by js2010 • edited Feb 13, 2021 by js2010

User contributions licensed under CC BY-SA 3.0