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

I am working on a script to deploy vendor software in a large environment. The first step is to stop service. The script works fine in our test environment, but I am not an administrator in the production environment, so I am convinced that this is a permission issue. I cannot get administrator rights for the prod environment, so I need to try to figure out everything that I may need to provide permissions for remote access to services. I make the following command to stop the 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

, rdp stop-service , . -, . ?

:   WMI, Stop-Service:

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

:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
+ CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
+2
2

,

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

, - moca

0

DCOM ? , PowerShell:

 invoke-command comp001 { stop-service adobearmservice }
0

Source: https://habr.com/ru/post/1531735/


All Articles