Retrieve internet proxy server address via PowerShell
I have to retrieve the proxy server address and port via PowerShell, so I can use the Invoke-Webrequest -uri http://some-site.com -Proxy
command. The expected output should looks like http://proxy-server.com:port.
I there a PowerShell function to retrieve the proxy server address and port, so we can use it in a script ?
Solution 1:
Here is the PowerShell function to achieve my goal :
function Get-InternetProxy
{
<#
.SYNOPSIS
Determine the internet proxy address
.DESCRIPTION
This function allows you to determine the the internet proxy address used by your computer
.EXAMPLE
Get-InternetProxy
.Notes
Author : Antoine DELRUE
WebSite: http://obilan.be
#>
$proxies = (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').proxyServer
if ($proxies)
{
if ($proxies -ilike "*=*")
{
$proxies -replace "=","://" -split(';') | Select-Object -First 1
}
else
{
"http://" + $proxies
}
}
}
Hope this helps !
Solution 2:
[System.Net.WebProxy]::GetDefaultProxy() | select address
[System.Net.WebProxy]
is an object and one of its static methods is GetDefaultProxy()
. The select
shows for us from all the columns, what interests us, and it is the address.
Solution 3:
Same host:
Get-ItemProperty -Path "Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
source: https://www.mowasay.com/2016/08/windows-check-proxy-settings-from-powershell/
Remote host(s):
Invoke-Command -ComputerName Member01, Server01 {Get-ItemProperty -Path 'HKLM:\SOFTWARE\VMware, Inc.\VMware Tools\' -Name InstallPath | select InstallPath
}
source: http://vcloud-lab.com/entries/powershell/powershell-get-registry-value-data