Powershell 输入PSSession不使用端口5986

Powershell 输入PSSession不使用端口5986,powershell,powershell-remoting,powershell-4.0,Powershell,Powershell Remoting,Powershell 4.0,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

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?

我遇到了这个问题

  • 检查防火墙规则。入站连接必须允许使用端口5986
  • 您是否在服务器上创建了证书?如果没有,那么。。。 以管理员身份在PowerShell中运行:

    New-SelfSignedCertificate -DnsName <your_server_dns_name_or_whatever_you_like> -CertStoreLocation Cert:\LocalMachine\My
    
    New SelfSignedCertificate-DnsName-CertStoreLocation证书:\LocalMachine\My
    
  • 并保存返回的指纹。你需要指纹

  • 您是否在服务器上配置了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>”}`
    
     winrm set winrm/config/client @{TrustedHosts="<ip_remote_server>"}
    
    winrm创建winrm/config/Listener?地址=*+Transport=HTTPS@{Hostname=“”;CertificateThumbprint=“”}`
    
  • 尝试登录到服务器:

    $so = New-PsSessionOption –SkipCACheck -SkipCNCheck
    Enter-PSSession -ComputerName <ip_address_or_dns_name_of_server>  -Credential <local_admin_username> -UseSSL -SessionOption $so
    
    $so=New PsSessionOption–SkipCACheck–skipncheck
    输入PSSession-ComputerName-Credential-UseSSL-SessionOption$so
    
  • 还可能需要为客户端配置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>”}`
    
     winrm set winrm/config/client @{TrustedHosts="<ip_remote_server>"}
    
    winrm集winrm/config/client@{TrustedHosts=”“}
    
    这似乎与中的问题相同,只是从不同的角度来看。请在服务器和客户端上显示
    winrm get winrm/config
    的输出。远程计算机是否已配置为对PSRM使用HTTPS?