gpt4 book ai didi

powershell - 到本地主机的 New-PSSession 失败

转载 作者:行者123 更新时间:2023-12-02 18:48:17 25 4
gpt4 key购买 nike

我有一个打开本地主机远程 session 的脚本。我需要通过登录脚本在某些设备上安装 NuGet。

$Username = "Admin"  
$Password = ConvertTo-SecureString ‘adminPW’ -AsPlainText -Force
$adminCredential = New-Object System.Management.Automation.PSCredential $Username, $Password
$Session = New-PSSession -Credential $adminCredential
Invoke-Command -Session $Session -ScriptBlock {Install-PackageProvider -Name NuGet -Verbose -MinimumVersion 2.8.5.201 -Force}

每次我尝试运行此程序时,都会收到以下错误:

New-PSSession : [localhost] 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 C:\Users\Mike Holtackers\OneDrive - Foreign Trade Association\Scripts\OutlookSig\getAADconnectionOK.ps1:5 char:12+ $Session = New-PSSession -ConnectionUri $ConnectionURI -Credential $a ...+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException    + FullyQualifiedErrorId : CannotConnect,PSSessionOpenFailed

运行 winrm Quickconfig 不会改变任何内容...

以下是 winrm get winrm/config 的输出

PS WSMan:\localhost\Listener\Listener_1084132640> winrm get winrm/configConfig    MaxEnvelopeSizekb = 500    MaxTimeoutms = 60000    MaxBatchItems = 32000    MaxProviderRequests = 4294967295    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 = *    Service        RootSDDL = O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)(AU;SA;GXGW;;;WD)        MaxConcurrentOperations = 4294967295        MaxConcurrentOperationsPerUser = 1500        EnumerationTimeoutms = 240000        MaxConnections = 300        MaxPacketRetrievalTimeSeconds = 120        AllowUnencrypted = false        Auth            Basic = false            Kerberos = true            Negotiate = true            Certificate = false            CredSSP = false            CbtHardeningLevel = Relaxed        DefaultPorts            HTTP = 5985            HTTPS = 5986        IPv4Filter = 194.168.254.1-194.168.254.256 [Source="GPO"]        IPv6Filter [Source="GPO"]        EnableCompatibilityHttpListener = false        EnableCompatibilityHttpsListener = false        CertificateThumbprint        AllowRemoteAccess = true [Source="GPO"]    Winrs        AllowRemoteShellAccess = true        IdleTimeout = 7200000        MaxConcurrentUsers = 2147483647        MaxShellRunTime = 2147483647        MaxProcessesPerShell = 2147483647        MaxMemoryPerShellMB = 2147483647        MaxShellsPerUser = 2147483647

最佳答案

检查 winrm 服务是否正在您的本地主机上运行:

PS C:\>  Get-Service winrm | ft -AutoSize

Status Name DisplayName
------ ---- -----------
Running winrm Windows Remote Management (WS-Management)

否则,尽管您已通过 winrm 配置并通过 Enable-PSRemoting 启用了 PS 远程处理,但 PS 远程处理将无法工作。

关于powershell - 到本地主机的 New-PSSession 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43498446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com