0

How do I configure Powershell upon first boot to use a Proxy Server for all Internet Access Requests?

I have a Windows 2016 server (in AWS) that I need to be able to access the Internet to download files on first boot to configure the applications. In this environment we have a Proxy Server. With the code below I can browse the Internet via IE and perform nslookup via PowerShell. All attempts to download files from various sites, including amazonaws.com fail and are reported as unreachable.

User Data:

    $AdminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
    $UserKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
    Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
    Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
    Rundll32 iesetup.dll, IEHardenLMSettings
    Rundll32 iesetup.dll, IEHardenUser
    Rundll32 iesetup.dll, IEHardenAdmin
    Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
    Write-Host "IE Enhanced Security Configuration (ESC) has been disabled."

    $reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings";
    Set-ItemProperty -Path $reg -Name ProxyServer -Value "proxy.int.mydomain.com:35899";
    Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1;

    netsh winhttp set proxy proxy-server="http://proxy.int.mydomain.com:35899"

    $env:HTTP_PROXY="http://proxy.int.mydomain.com:35899"
    $env:HTTPS_PROXY="http://proxy.int.mydomain.com:35899" 

    curl google.com

Here is the error message received:

 
    PS C:\Users\Administrator> curl google.com
    curl : Unable to connect to the remote server
    At line:1 char:1
    + curl google.com
    + ~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Note: Domain name and ports were changed to protect the innocent.

  • Invoke-WebRequest applet (aliased as curl in powershell) doesn't use the environment variables and need the use of a -Proxy parameter as far as I know as it has no default value: See the parameter description on docs.microsoft.com/en-us/powershell/module/… – Tensibai Sep 21 '18 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.