Powershell Inovke和Enter-PSSession命令在5985和5986以外的其他端口上执行

时间:2017-09-11 14:04:30

标签: powershell winrm

我们的环境中阻止了端口5985和5986,我需要备用端口     使用不同的方法执行InvokeEnter-PSSession命令的解决方案     端口(如3389)。

winrm get winrm/config/client的输出:

Client
NetworkDelayms = 5000
URLPrefix = wsman
AllowUnencrypted = false
Auth
    Basic = true
    Digest = true
    Kerberos = true
    Negotiate = true
    Certificate = true
    CredSSP = false
DefaultPorts
    HTTP = 5985
    HTTPS = 5986
TrustedHosts

错误:

get-wsmaninstance : The WinRM client received an unknown HTTP status code 
from the remote WS-Management service. 
 At line:1 char:1
+ get-wsmaninstance -enumerate wmicimv2/win32_service -computername 
sadcm0000078:8 ...

1 个答案:

答案 0 :(得分:0)

事后才觉得这是一个足够的答案:

-Port cmdlet上有-PSSession个参数。您可以指定所需的端口,但是您需要配置端点以更改它正在侦听的端口。

PS C:\> Get-Help New-PSSession -Parameter Port

-Port <Int32>
    Specifies the network port on the remote computer that is used for this connection. To connect to a remote
    computer, the remote computer must be listening on the port that the connection uses. The default ports are 5985,
    which is the WinRM port for HTTP, and 5986, which is the WinRM port for HTTPS.

    Before using another port, you must configure the WinRM listener on the remote computer to listen at that port.
    Use the following commands to configure the listener:

    1. `winrm delete winrm/config/listener?Address=*+Transport=HTTP`

    2. `winrm create winrm/config/listener?Address=*+Transport=HTTP @{Port="<port-number>"}`

    Do not use the Port parameter unless you must. The port setting in the command applies to all computers or
    sessions on which the command runs. An alternate port setting might prevent the command from running on all
    computers.

    Required?                    false
    Position?                    named
    Default value                None
    Accept pipeline input?       False
    Accept wildcard characters?  false
相关问题