I have an error using powershell

MGUENDOUZI 66 Reputation points

Hello everyone, when I run this command

"Get-Service -ComputerName XXX -displayName XXX | Restart-Service -Verbose"

I have the following error?

Get-Service : Cannot open Service Control Manager on computer 'XXX'. This operation might require other
At line:1 char:1

  • Get-Service -ComputerName XXX -displayName XXX ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Get-Service], InvalidOperationException
  • FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand

how can i run a get-service command from one server to another

Thanks all

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
6,335 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,180 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Bjoern Peters 8,731 Reputation points


    the answer is already displayed in the error message ;-)

    This operation might require other privileges.

    Make sure that the user who is executing your command has administrative rights on that remote computer.
    Actually, it seems that your user is missing those permissions, therefore you are getting this error message.

    If your user is a member of the domain admin group then you might try to execute that command/script "as an administrator".

  2. Olaf Helper 36,191 Reputation points

    This operation might require other privileges.

    It requires admin permission to get the informations from a remote machine; do you have them?

  3. MGUENDOUZI 66 Reputation points

    thank you for your answer, but the user is indeed administrator of the virtual machine, I tried with the local admin account it sends the same error message

    0 comments No comments

  4. Rich Matheisen 42,996 Reputation points

    It looks like you're restarting ALL the services on the remote computer. The Restart-Service cmdlet sends a "stop" followed (after waiting for the service to stop) by a "start". That'll work until you stop the "Server" service on the remote computer. But it's the "server" service on the remote computer that does the stopping and starting of the services, and now it's stopped! You'll need to start the server service now, but I think you'll have to do that manually.

    You can avoid this by piping the output from Get-Service into Where-Object and allowing only service names other than "server" to be piped to the Restart-Service cmdlet.

  5. Rich Matheisen 42,996 Reputation points

    Try this:

        Get-Service -ComputerName XXX| Where-Object {$_.displayname -ne 'server'} | Restart-Service  

    NOTE: There are probably other services that you'll need to omit in order to maintain the ability to PowerShell remoting and use things like WMI.

    What is it you're trying to do by restarting every service? Wouldn't it be easier to just restart the remote machine?

    0 comments No comments