Josh-CO Dev

Solving the worlds problems one line of code at a time.

Powershell – Set a Proxy

Leave a comment


I’ve been using Powershell A LOT lately and I thought I would start sharing some code snippets of things that I have had to learn along the way. The first thing is how to set up powershell to use a proxy. A lot of the scripts I have been writing involve going out to the web and scrubbing HTML as a data source. It is pretty simple. Just add this to your script (I always put it at the top out of habit, not sure if this is necessary).

#Set our proxy information. We are hardcoding the proxy server, but the credentials will pull from the OS
$global:PSDefaultParameterValues = @{
        'Invoke-RestMethod:Proxy'='http://proxyServer:proxyPort'
        'Invoke-WebRequest:Proxy'='http://proxyServer:proxyPort'
        '*:ProxyUseDefaultCredentials'=$true
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s