Powershell: `Enter-PSSession -ContainerId $id` returns `Object reference not set to an instance of an object.`

Created on 5 Jan 2018  路  7Comments  路  Source: PowerShell/PowerShell

Enter-PSSession -ContainerId $id returns Object reference not set to an instance of an object..

Steps to reproduce

  1. Create a windows docker container like: microsoft/powershell:windowsservercore from https://hub.docker.com/r/microsoft/powershell/

  2. open PSCore and run:

Enter-PSSession -ContainerId $theContainersId

Expected behavior

We see the prompt of the remote machine

Actual behavior

Enter-PSSession : Object reference not set to an instance of an object.
At line:1 char:1
+ Enter-PSSession -ContainerId (Get-Container adoring_gates).ID
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Enter-PSSession], PSInvalidOperationException
+ FullyQualifiedErrorId : CreateRemoteRunspaceForContainerFailed,Microsoft.PowerShell.Commands.EnterPSSessionCommand

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-rc.2
PSEdition                      Core
GitCommitId                    v6.0.0-rc.2
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
WG-Remoting

All 7 comments

This is not happening any more, but now I get Enter-PSSession : The input ContainerId 95e675615810aa55373b61270e710f3dd8d5e6aeab8d8aa51194cd3d22046f4b does not exist, or the corresponding container is not running. in 6.0.2 and the daily build although the container is definitely running. I did:

docker run -it microsoft/windowsservercore powershell # in any shell
docker ps --no-trunc # to get full container id
# Open pwsh in a new shell
Enter-PSSession -ContainerId $theContainersId

Did I do anything wrong?

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.731
PSEdition                      Core
GitCommitId                    v6.1.0-preview.731
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

You have to be running elevated, or it won't work. This seems very ... broken.

Looks like the Hyper-V team changed the namespace and schema of a dependent hyper-v type without telling us. I'll have this fixed.

Hyper-V is the one requiring elevation as the container is started with elevation so connecting to it requires elevation. I agree that more things in Windows should not require elevation.

Yeah, but docker exec commands against the container don't require elevation, so ...

Hello,

I have the exact similar problem in the latest 7.0 version.

PS C:\Windows\System32> New-PSSession -ContainerId 562f5119c59fb4f014665126345be0b37499267dfccd3efd4bd19b0b82af6adc -RunAsAdministrator
New-PSSession: Object reference not set to an instance of an object. 
PS C:\Windows\System32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The same command on the same server with Powershell.Core 3.0 runs fine.

Kind regards,

Bart Bourgeois

@BartBourgeois The fix was included in 7.0.0, so I'm not sure why you are seeing the issue again. /cc @SteveL-MSFT

The same command on the same server with Powershell.Core 3.0 runs fine.

What do you mean by Powershell.Core 3.0?

Dear @daxian-dbw ,

I did find the solution for this! Although it was quite a ride.
I need a fix quick, so decided to convert my application to Full dotnet standard instead of Core, expected it to work. But on that exact system I got an entirely different error.

New-PSSession : Unable to load DLL 'vmcompute.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

After searching for this obscure error, I was able to to find a tread that provided the solution.
https://github.com/Microsoft/AL/issues/2715#issuecomment-400237137

After unstalling the "Containers" Windows feature, rebooting, installing "Containers" again and rebooting, the obscure vmcompute error was solved.

With this fix, decided to go back to the dotnet Core version of my application, which also works now!
So it seems the problem was with the "Containers" windows feature all along.

**Solution:**
- Remove windows feature "Containers"
- Reboot server
- Install windows feature "Containers"
- Reboot server

Hopefully this information can help out others.

Kind regards,

Was this page helpful?
0 / 5 - 0 ratings