Skip to content

Instantly share code, notes, and snippets.

@milesgratz
Last active April 12, 2017 15:26
Show Gist options
  • Save milesgratz/a6b27737367596167783154483ee5146 to your computer and use it in GitHub Desktop.
Save milesgratz/a6b27737367596167783154483ee5146 to your computer and use it in GitHub Desktop.
Use-Proxy function suggestion (#powershell irc-bridge)
Function Use-Proxy {
$proxy = 'http://my.proxy.server:80/'
$WebRequest_params = @{
Uri = 'http://www.example.com'
Method = 'Head'
DisableKeepAlive = $true
UseBasicParsing = $true
}
Try {
Invoke-WebRequest @WebRequest_params -ErrorAction Stop
return $false
}
Catch { $null }
Try {
Invoke-WebRequest @WebRequest_params -Proxy $proxy -ErrorAction Stop
return $proxy
}
Catch { Write-Error "Unable to connect to $($WebRequest_params.Uri). Check internet connection or proxy setting." }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment