Windows – Set proxy for all users and system accounts on Windows Server

powershellPROXYwindowswindows-server-2016

We are trying to deploy a ARM template for Azure. We want to set the proxy for all users and system accounts. But we are unable to do it.
When we use this powershell script, the current user has a proxy but not the system account. Any suggestions?

<#
.Synopsis
This function will set the proxy settings provided as input to the cmdlet.
.Description
This function will set the proxy server and (optinal) Automatic configuration script.
.Parameter ProxyServer
This parameter is set as the proxy for the system.
Data from. This parameter is Mandatory
.Example
Setting proxy information
Set-InternetProxy -proxy "proxy:7890"
.Example
Setting proxy information and (optinal) Automatic Configuration Script 
Set-InternetProxy -proxy "proxy:7890" -acs "http://proxy:7892"
#>

#[CmdletBinding()]
Param(        
    [Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [String[]]$Proxy,

    [Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [AllowEmptyString()]
    [String[]]$acs      
)

Begin
{
    $regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"        
}    
Process
{        
    Set-ItemProperty -path $regKey ProxyEnable -value 1
    Set-ItemProperty -path $regKey ProxyServer -value $proxy

    if($acs) 
    {            
        Set-ItemProperty -path $regKey AutoConfigURL -Value $acs          
    }

    #$obj = Get-ItemProperty -Path Registry::”HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" -Name DefaultConnectionSettings -Value $obj.DefaultConnectionSettings
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections" -Name SavedLegacySettings -Value $obj.SavedLegacySettings
    #$obj = Get-ItemProperty -Path Registry::”HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value $obj.ProxyEnable
    #Set-ItemProperty -Path Registry::”HKEY_USERS\S-1-5-18\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name Proxyserver -Value $obj.Proxyserver
}     
End
{
    Write-Output "Proxy is now enabled"
    Write-Output "Proxy Server : $proxy"

    if ($acs)
    {
        Write-Output "Automatic Configuration Script : $acs"
    }
    else
    {
        Write-Output "Automatic Configuration Script : Not Defined"
    }
}

Best Answer

According to the script above, you've remmed out the keys you need.

You're setting the wrong key. Try this one:

Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\DefaultConnectionSettings

On this key:

HKEY_USERS\S-1-5-18

And you should be golden!