Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用现有会话输入PSSession_Powershell - Fatal编程技术网

Powershell 使用现有会话输入PSSession

Powershell 使用现有会话输入PSSession,powershell,Powershell,我用$remote=New psseion创建了一个会话。。。我想以后以交互方式使用它 我尝试输入psseion-Session$remote,但它抱怨输入PSSession:无法使用指定的命名参数解析参数集。使用Id参数时也会发生同样的情况 ==编辑=== > New-PSSession Id Name ComputerName ComputerType State ConfigurationName Availability

我用$remote=New psseion创建了一个会话。。。我想以后以交互方式使用它

我尝试输入psseion-Session$remote,但它抱怨输入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

如问题注释中所述,出现此异常的原因是您将自定义函数包装在Enter-PSSession cmdlet周围。您的自定义函数显然总是指定-ComputerName参数,即使您没有使用它


由于-Session是与-ComputerName不同的参数集中的一个参数,因此除非您相应地修改围绕Enter-PSSession的包装,否则您将无法使用它。

是否使用其他参数?我只是在我的测试环境中测试了它,一切正常。我的环境的输出在下面的注释中。另外,只要重新阅读你的问题,看起来你在新的会话中缺少了一个S。您有New-PSSession.PS C:\WINDOWS\system32>$dc1remote=New-PSSession-VMName dc1-Credential timhaintz\administrator PS C:\WINDOWS\system32>输入PSSession$dc1remote[dc1]:PS C:\Users\administrator\Documents>退出PS C:\WINDOWS\system32>输入PSSession-会话$dc1remote[dc1]:PS C:\Users\Administrator\Documents>exitWhat是您的PS版本,您能显示完整会话定义的外观吗。。。如果愿意,请清除。上面添加的输出是否使用了与Enter-PSSession Cmdlet冲突的powershell配置文件?我见过有人将cmdlet包装到同名函数中,为参数提供自己的默认值。您能否验证“etsn”别名是否指向Enter-PSSession Cmdlet?