Enter-PSSession
命令在端口为5985的远程PC上工作,但每当我指定端口5986(HTTPS)时,它都会显示以下错误:
Enter-PSSession : Connecting to remote server localhost failed with the
following error message : The client cannot connect to the destination
specified in the request. Verify that the service on the destination is
running and is accepting requests. Consult the logs and documentation for
the WS-Management service running on the destination, most commonly IIS
or WinRM. If the destination is the WinRM service, run the following
command on the destination to analyze and configure the WinRM service:
"winrm quickconfig". For more information, see the
about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter-PSSession -ComputerName localhost -Port 5986
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (localhost:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
我曾尝试在防火墙中启用端口5986甚至完全禁用防火墙,但仍然无法解决问题。那么,如何为PSSession启用端口5986?
答案 0 :(得分:1)
我遇到了这个问题。
您是否在服务器上创建了证书?如果不是那么...... 以管理员身份在PowerShell中运行:
New-SelfSignedCertificate -DnsName <your_server_dns_name_or_whatever_you_like> -CertStoreLocation Cert:\LocalMachine\My
并保存返回的指纹。你需要Thumbprint。
您是否在服务器上配置了WinRM?如果没有则...以管理员身份运行cmd.exe并运行它:
winrm create winrm/config/Listener?Address=*+Transport=HTTPS @{Hostname=”<your_server_dns_name_or_whatever_you_like>”; CertificateThumbprint=”<certificate_thumbprint_from powershell>”}`
尝试登录服务器:
$so = New-PsSessionOption –SkipCACheck -SkipCNCheck
Enter-PSSession -ComputerName <ip_address_or_dns_name_of_server> -Credential <local_admin_username> -UseSSL -SessionOption $so
也可能需要为客户端配置winrm。以管理员身份运行cmd.exe并运行它:
winrm set winrm/config/client @{TrustedHosts="<ip_remote_server>"}