Last active
April 12, 2017 15:26
-
-
Save milesgratz/a6b27737367596167783154483ee5146 to your computer and use it in GitHub Desktop.
Use-Proxy function suggestion (#powershell irc-bridge)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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