2

So I'm trying to use Invoke-Command to run a command on a remote server in Azure. To test, I'm using a super simple script:

Invoke-Command -ComputerName MyServer -ScriptBlock { Write-Output "HI"}

I've run this command on a whole bunch of other servers that are configured identically (as far as I can tell), and they all run in a second or less. For this particular server, it takes 2 minutes or more. I can't figure out why. It does eventually execute properly, but it takes forever to establish the remote pssession.

Some things I've tried/verified:

  • Powershell version is identical on this machine and others (5.1.14393). OS version is the same.
  • I've tried completely disabling Windows firewall, no luck
  • I've tried using explicit credentials instead of Kerberos
  • Network adapter settings/IP 4 settings are identical on all machines. It doesn't matter if the servers are on the same subnet or not.
  • FROM the problem machine I can Invoke-Command remotely to other machines just fine (< 1 second execution). On the problem machine, invoke-command to itself takes 2+ minutes
  • I've tried setting PSSessionOptions with options as described here.
  • Tried using ISE vs command line, no difference
  • Tried using enter-pssession, no difference
  • Tried using psexec on this and other servers. It works, takes about 20-30 seconds, but is consistent across all servers, including the problem server.
  • I've restarted the WinRM service, rebooted the machine, redeployed the machine in Azure, no dice.
  • DISM and SFC to repair image and installed files

As far as I can tell, the machine is identical to its "brother" that was set up at a similar time, in the same way, on the same subnet, with the same routing rules. The only difference is the machine size, but I've queried other machines of different sizes and they work as expected.

I'm out of ideas. Thoughts?

Chris
  • 443
  • 1
  • 3
  • 14
  • In lieu of figuring out what the actual problem is here, I created a brand new Azure VM using our standard runbook (i.e. it's identical to the current problem machine) and the invoke-command script works now in ~1 seconds, like the other functional machines. I'm still not sure what's up with the old guy. – Chris Sep 24 '19 at 17:48

1 Answers1

0

I had similar issues to this: the commands seemed to just hang. Turns out it was the proxy.

Use the following line in your script to bypass it:

netsh winhttp reset proxy
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83