2017-10-06 34 views
0

我創建了一個與$remote = New-PsSesion ...的會話,我想稍後以交互方式使用它。Enter-PSSession與現有會話

我試過Enter-PSSesion -Session $remote但它報錯Enter-PSSession:使用指定的命名參數無法解析參數集。使用Id參數時會發生同樣的情況。

===編輯===

> 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 
+1

您是否使用任何其他參數?我只是在我的測試環境中測試它,並且它都正常工作。在我的環境下輸出以下評論。此外,只需重新閱讀您的問題,看起來您在New-PSSession中缺少S。你有New-PSSesion。 –

+0

PS C:\窗口\ system32> $ dc1remote =新-的PSSession -VMName DC1 -Credential timhaintz \管理員 PS C:\窗口\ system32>輸入-的PSSession $ dc1remote [DC1]:PS C:\用戶\ Administrator \ Documents>退出 PS C:\ WINDOWS \ system32> Enter-PSSession -Session $ dc1remote [dc1]:PS C:\ Users \ Administrator \ Documents>退出 –

+0

什麼是您的PS版本,您可以顯示什麼你完整的會話定義看起來像......如果你願意的話,可以擦掉。 – Matt

回答

1

正如在評論你的問題說,你得到這個異常的原因是,你纏Enter-PSSession cmdlet的自定義功能。即使您不使用它,您的自定義功能顯然始終指定-ComputerName參數。

由於-Session是來自與-ComputerName不同的參數集的參數,因此您將無法使用它,除非您相應地在Enter-PSSession左右修改包裝。