title: Enabling Proxy server using Powershell remoting
body: <p>I am trying to add a Proxy server to a remote server(ServerB) using PowerShell Remoting. However each time, the proxy is cleared after being set. Below is the code which I use:</p>
  <pre><code>Invoke-command -computername ServerB -authentication Negotiate -scriptblock{$regKey=&quot;HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings&quot;
  $proxyServer = &quot;&quot;
  $proxyServerToDefine = 'our.proxy.server:port'
  
  $proxyServer = Get-ItemProperty -path $regKey ProxyServer -ErrorAction SilentlyContinue
  if([string]::IsNullOrEmpty($proxyServer))
  {
      Set-ItemProperty -path $regKey ProxyServer -value $proxyServerToDefine
      Set-ItemProperty -path $regKey ProxyEnable -value 1
  
      #The only way I've found to get the proxy settings to apply is to start ie in some way.
          $ie = New-Object -ComObject internetexplorer.application
          $ie.Quit()
  
      Remove-Variable -Name ie
      
      Write-Verbose &quot;Proxy is now enabled&quot;
  }
  else
  {
      Write-Verbose &quot;Proxy Server already present&quot;
  }
  }
  </code></pre>
  <p>The proxy is being cleared after I have instantiated the 'ie' object.
  I have tried to enable the Proxy by running the above code(proxy enable code section) inside PowerShell remote session(using <code>Enter-PSSession</code>), however this has not resolved my issue.</p>
  <p>Above code works fine for me if I login to the server and runs it from there.</p>