New-PSSession to localhost fails

Docschnitzel

I have a script that opens a remote session to the localhost. I need this to install NuGet on some devices from within a logonscript.

$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}

Every time I try to run this I get the following error:

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

Running winrm quickconfig does not change anything...

Following is the output of winrm get winrm/config

PS WSMan:\localhost\Listener\Listener_1084132640> winrm get winrm/config
Config
    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
Docschnitzel

Issue was someone had tampered with the firewall... Thanx for the help guys!

Basically the firewall GPO was blocking remote management

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

New-PSSession Fails Ubuntu to Windows using .NET Core Packages

New-PSSession Parellel Execution

PowerShell Core Script deployed as AWS Lambda function fails to remote connect into Windows EC2 Instance using the Commandlet new-pssession

File operation failed with New-PSSession

New-PSSession Cmdlet using Oauth credentials

New-PSSession does not work locally

Enter-PSSession to remote server fails with "cannot find the computer"

PowerShell 5.1 What is wrong with my New-PSSession syntax

Copy-Item from New-PSDrive within PSSession

New-MailboxExportRequest don't work in remote PSsession

Error: new-PSSession:One or more computer names is not valid

Why is invoke-command and new-pssession not working?

New-PSSession using python only (no subprocess module)

winsock fails to connect to localhost

NativeScript, Android - connection to localhost fails

django selenium fails to load localhost

nginx in docker fails to talk to localhost

Exporting a database in phpmyadmin fails (localhost)

What if new fails?

Appending a new trace fails

New fields work on localhost but not on Heroku

On Google Colab, localhost access from Javascript fails

TailwindCSS visibility toggle on hover fails only on localhost

Yosemite localhost resolver and dnsmasq fails offline

A foreign key constraint fails on production but not on localhost

Nativescript localhost http call fails on iOS

Rails with Devise, works fine on localhost, fails on Heroku

Socket.io Handshake fails on site but not on localhost

Why "xterm -display localhost:0.0" fails