I have an error using powershell

MGUENDOUZI 66 Reputation points
2022-10-24T11:54:06.773+00:00

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
privileges.
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.
8,135 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,581 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Bjoern Peters 8,886 Reputation points
    2022-10-24T12:10:00.317+00:00

    Hi @MGUENDOUZI

    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 45,371 Reputation points
    2022-10-24T12:11:41.023+00:00

    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
    2022-10-24T12:29:15.817+00:00

    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 47,471 Reputation points
    2022-10-24T18:12:47.79+00:00

    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 47,471 Reputation points
    2022-10-24T19:49:26.683+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.