Archive for the ‘Coding’ Category

PowerShell and Proxy Auto Detect Problem

August 24, 2010

Just a quick one about this issue that has been plaguing me for ages. Like many people in corporate world, the browser on our corporate build is configured to point to an “automatic configuration script”. But perhaps unlike many corporates, the script at the place I work is f_huge_. And for some reason, this has introduced a problem for a particular .NET assembly that is associated with the System.Web namespace… the same namespace that is used by PowerShell when making web connections, such as when you invoke Connect-VIServer in PowerCLI.

The result is that powershell.exe starts chewing up memory like there’s no tomorrow… basically until your entire machine hangs. Lucky for me I don’t need to use PowerShell in anger on a daily basis, but this problem was enough for me to resort to running a vanilla XP VM whenever I needed to do stuff with PowerShell. But thankfully, someone took the initiative and looked into the problem with Microsoft, discovered the root cause, and a workaround. And so let it be known that I don’t get any credit for this post, but the person who should cannot be named for stupid corporate communications policy reasons.

And so here’s the workaround. Basically, you need to add the following to the powershell.exe.config file in the same directory as the powershell executable (both locations if you’re on an x64 machine – just create the file if it’s not there):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.net>
  <defaultProxy>
   <proxy autoDetect="false"/>
  </defaultProxy>
 </system.net>
</configuration>

Et voila! Problem solved. Not sure if any other .NET apps are affected by this, but any PowerShell scripts that directly invoke System.Web.Client (for example) will be – I have a script to grab UUIDs via the iLO interface of HP boxes, and got the same problem whenever I invoked that script. But not anymore, hooray!

Advertisements