title: Powershell stop-service error: cannot find any service with service name
body: <p>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:</p>
  
  <pre><code>Stop-Service -InputObject $(Get-Service -Computer $destination.Server -Name ("moca."+$destEnv))
  </code></pre>
  
  <p>When I run the script I get:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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?</p>
  
  <p>Edit:
   A coworker suggested using WMI so tried replacing the Stop-Service line with:</p>
  
  <pre><code>(Get-WmiObject -computer $destination.Server Win32_Service -Filter ("Name='moca."+$destEnv+"'")).InvokeMethod("StopService",$null)
  </code></pre>
  
  <p>and I get:</p>
  
  <pre><code>Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
  + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
  </code></pre>