Can't use Get-Service –ComputerName on remote computer Can't use Get-Service –ComputerName on remote computer powershell powershell

Can't use Get-Service –ComputerName on remote computer


With PowerShell V2 you've got two approachs for remote commands.

Commands with built-in remoting :

A small set of commands in PowerShell v2 have a -ComputerName parameter, which allows you to specify the target machine to access.

Get-ProcessGet-ServiceSet-ServiceClear-EventLogGet-CounterGet-EventLogShow-EventLogLimit-EventLogNew-EventLogRemove-EventLogWrite-EventLogRestart-ComputerStop-ComputerGet-HotFix

These commands do their own remoting either because the underlying infrastructure already supports remoting or they address scenarios that are of particular importance to system management. They are built on the top of DCOM and, on the access point of view, you can use them when you can establish a session with the remote machine with commands like NET.exe or PSExec.exe.

You are trying to use one of them and you've got a problem with credentials (-cred parameter), because your token credentials can't be used to establish an admin session to the remote machine.

The PowerShell remoting subsystem :

Before you can use PowerShell remoting to access a remote computer, the remoting service on that computer has to be explicitly enabled. You do so using the Enable-PSRemoting cmdlet. If you are working in workgroup you also need to enable the server to enter on your client computer with this command (on your client computer as administrator):

Set-Item WSMan:\localhost\Client\TrustedHosts *

Then, you will use New-PSSession Cmdlet (with -computername and -credentials) to create a session object. Then Invoke-Command (with -session and -scriptblock) cmdlet allows you to remotely invoke a scriptblock on another computer. This is the base element for most of the features in remoting. You can also use Enter-PSSession to establish an interactive (SSL like) PowerShell command line with the server.

Useful link : Layman’s guide to PowerShell 2.0 remoting


Test this :

$sess = New-PSSession -ComputerName myServer-Credential (Get-Credential)Invoke-Command -Session $sess -ScriptBlock {get-service}...Remove-PSSession -Session $sess


If it is still important, here is my workaround:

I got an unprivileged user called 'usser' who wants powershell(v2) remoting from client A to server B.

Steps:

  1. enable-psremoting on Targetserver B as admin
  2. Set-PSSessionConfiguration -Name Microsoft.PowerShell -ShowSecurityDescriptorUI on Targetserver B as admin
  3. Add "usser" with full privileges

Now comes the exciting part:

  1. sc sdshow scmanager on Targetserver B as admin

  2. Copy the SDDL output

  3. sc sdset scmanager (f.e.:)"D:(A;;CC;;;AU)(A;;CCLCRPRC;;;IU)(A;;CCLCRPRC;;;SU)(A;;CCLCRPWPRC;;;SY)(A;;KA;;;BA)S:(AU;FA;KA;;;WD)(AU;OIIOFA;GA;;;WD)" , in the Output you have to fill after this part (A;;CCLCRPWPRC;;;SY) this = (A;;KA;;;SID)

  4. SID stands of course for the SID of the unprivileged "usser"-user

  5. when everything should be fine, it will similiar looks like this :

    D:(A;;CC;;;AU)(A;;CCLCRPRC;;;IU)(A;;CCLCRPRC;;;SU)(A;;CCLCRPWPRC;;;SY)(A;;KA;;;S-1-5-21-4233383628-1788409597-1873130553-1161)(A;;KA;;;BA)S:(AU;FA;KA;;;WD)(AU;OIIOFA;GA;;;WD)

Hope you will enjoy that little but complicated workaround.


Viewing and manipulating services requires administrative privileges on the target machine.

I was able to duplicate your error message by attempting to run Get-Service -ComputerName MyServer while logged in as a user account that doesn't have administrative rights to the server in question.

You can resolve this by either granting the workstation user account administrative privileges on the target server or by creating a a local group on the server and granting invocation privileges to members of that group. If you want to do the latter, see the following article.

msgoodies: Using a PS Session without having Administrative Permissions