majkinetor
majkinetor

Reputation: 9056

Enter-PSSession with existing session

I created a session with $remote = New-PsSesion ... and I want to use it later interactively.

I tried Enter-PSSesion -Session $remote but it complains Enter-PSSession : Parameter set cannot be resolved using the specified named parameters. The same happens when using Id parameter.

=== EDIT ===

> New-PSSession

 Id Name            ComputerName    ComputerType    State         ConfigurationName     Availability
 -- ----            ------------    ------------    -----         -----------------     ------------
  1 Session1        localhost       RemoteMachine   Opened        Microsoft.PowerShell     Available



> etsn -Id 1
Enter-PSSession : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ etsn -Id 1
+ ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Enter-PSSession], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.EnterPSSessionCommand


> $host


Name             : ConsoleHost
Version          : 5.1.14393.1198
InstanceId       : ab8e55cd-69ae-4587-a70a-c66f197028a4
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : sr-Latn-RS
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Upvotes: 0

Views: 950

Answers (1)

Manuel Batsching
Manuel Batsching

Reputation: 3616

As stated in the comments to your question, the reason you get this exception is that you wrapped your custom function around the Enter-PSSession cmdlet. Your custom function apparently always specifies the -ComputerName parameter, even if you are not using it.

As -Session is a parameter from a different parameter set than -ComputerName you will not be able to use it unless you modify your wrapper around Enter-PSSession accordingly.

Upvotes: 1

Related Questions