I have a windows 2003 box setup with virtual box and I can’t powershell to work with it.
I try this on my windows 7 machine
Get-Service –ComputerName myserver
I get back
Get-Service : Cannot open Service Control Manager on computer 'myserver'. This operation might require other privileges.
At Script1.ps1:2 char:4
+ gsv <<<< -cn myserver
+ CategoryInfo : NotSpecified: (:) [Get-Service], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand
While searching around I found I should try and use Enable-PSRemoting.
I did this and now when I try to use it I get
WinRM already is set up to receive requests on this machine. WinRM
already is set up for remote management on this machine.
Yet I still get the same error. Is this because I am using a virtual machine? I setup the virtual OS to be on my domain and I can even use my AD account credentials to log in.
I can get other information back from it.
So it is not like I can’t connect to it with powershell.
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
-ComputerNameparameter, which allows you to specify the target machine to access.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.exeorPSExec.exe.You are trying to use one of them and you’ve got a problem with credentials (
-credparameter), 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-PSRemotingcmdlet. 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):Then, you will use
New-PSSessionCmdlet (with-computernameand-credentials) to create a session object. ThenInvoke-Command(with-sessionand-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 :