In a local network, a computer with ip 192.168.0.146 name Analytic5. On my win10 pc, on user win7 Trying to restart the print service:

Get-Service -Name Spooler -ComputerName Analytic5 | Restart-Service 

I get an error:

 Get-Service : Не удается найти службу с именем службы "Spooler". строка:1 знак:1 + Get-Service -Name Spooler -ComputerName Analytic5 | Restart-Service + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Spooler:String) [Get-Service], ServiceCommandException + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand 
  • and the service is exactly? - Senior Pomidor
  • @Senior Automator did not understand you - upward
  • go to the remote computer and run Get-Service -Name Spooler and make sure that there is a service with that name for sure - Senior Pomidor
  • @Senior Automator I changed to the one that is spoolsv.exe but the error is the same spoolsv.exe - upward
  • but you never answered that the Get-Service -Name Spooler , executed locally on the Analytic5 machine - Senior Pomidor

1 answer 1

Restart-Service as Start-Service , as well as Stop-Service can be used only to the local computer. Accordingly, passing through the channel, the object with the description of the 'Spooler' service is applied by the Restart-Service cmdlet to the local computer.

In this situation, I advise you to use WMI, like this:

 $WMI = Get-WmiObject Win32_Service -Filter "Name = 'Spooler'" -ComputerName Analytic5 -Credential (Get-Credential) $WMI.StopService() $WMI.StartService() 

If WMI is not allowed for some reason, but WinRM is available, you can use the Invoke-Command cmdlet, like this:

 Invoke-Command -ScriptBlock {Get-Service -Name Spooler | Restart-Service} -ComputerName Analytic5 -Credential (Get-Credential)