Proxy

Run PowerShell through a Proxy

Posted by robd on August 27, 2019
powershell, Proxy / 1 Comment

At work I’m behind a proxy which caused me havock when trying to install modules into PowerShell.

That was until I found this amazing script to tell PowerShell to use a proxy.

First open your PowerShell profile by either doing this in PowerShell:

notepad $PROFILE

Or open “Microsoft.PowerShell_profile.ps1” and  “Microsoft.PowerShellISE_profile.ps1” in Explorer with notepad:

C:\Users\%Username%\My Documents\WindowsPowerShell

Once open, paste in the following, editing the proxy address and port.

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://ProxyName:ProxyPort')

[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

This will use your current credentials you’re logged in with to pass the commands to the proxy server.

Test with a

update-help

 

Tags: , ,

WPAD Proxy Reset

Posted by robd on October 26, 2017
Proxy, Windows 7 / No Comments

Had a strange problem where the proxy was forcing IE to an incorrect proxy server so to fix:

1.Clear the Internet Explorer cache completely: ActiveX Controls, Cookies, History, etc..

2.Close all instances of Internet Explorer.

3.Delete all WPAD script instances. Open a command window as administrator and type the following command:

del \wpad*.dat /s

4.Clear the DNS and Netbios name caches. Open a command window as administrator and type the following commands:

ipconfig /flushdns

nbtstat –R

Done.

Tags: , ,

Enable and Disable Internet Explorer Proxy via Script

Posted by robd on May 15, 2012
Proxy / No Comments

Some of you may have the common moan from users that when they are at home their internet doesn’t work on their corporate laptop.

They tell you they’ve connected to their wireless without issue but IE won’t work!

Straight away you ask “Have you turned off your Proxy?”, then they blankly stare at you!

So…. The solution is to make a VB script such as the below to turn it off and on depending whether they are sat in work or at home:

Note: The script enables or disables the proxy via the registry so the user needs access to their registry!!

Turn the proxy on (for work):

 

Set WshShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
	"CurrentVersion\Internet Settings\ProxyEnable", _
	1, "REG_DWORD"

wShshell.Run "taskkill /im iexplore.exe",0,True
Set wShshell = Nothing

Mybox = MsgBox("Proxy is now Enabled" ,vbOkOnly,"Proxy Enabled")

Turn the proxy off (for home):

Set WshShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

WshShell.RegWrite "HKCU\Software\Microsoft\Windows\" & _
	"CurrentVersion\Internet Settings\ProxyEnable", _
	0, "REG_DWORD"

wShshell.Run "taskkill /im iexplore.exe",0,True
Set wShshell = Nothing

Mybox = MsgBox("Proxy is now disabled" ,vbOkOnly,"Proxy Disabled")

 

Tags: