-
Notifications
You must be signed in to change notification settings - Fork 1
/
Set-Proxy.ps1
76 lines (69 loc) · 1.86 KB
/
Set-Proxy.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
function Set-Proxy
{
[CmdletBinding()]
[OutputType([int])]
Param
(
# Param1 help description
[Parameter(ValueFromPipelineByPropertyName=$true,
Position=0)]
$proxy = "http://10.201.0.27:801"
, # If you want to permenantly set this. reqires restart
[switch]
$global
, # SSID to automatically detect
[string]
$SSID
)
Begin
{
function setProxyConfiguration
{
if($global){
[environment]::SetEnvironmentVariable("http_proxy", $proxy, "User")
[environment]::SetEnvironmentVariable("https_proxy", $proxy, "User")
} else {
$env:http_proxy = $proxy
$env:https_proxy = $proxy
}
git config --global --add http.proxy $proxy
git config --global --add https.proxy $proxy
}
function removeProxyConfiguration
{
if($global){
[environment]::SetEnvironmentVariable("http_proxy", $null, "User")
[environment]::SetEnvironmentVariable("https_proxy", $null, "User")
} else {
Remove-Item env:http_proxy
Remove-Item env:https_proxy
}
git config --global --remove-section http
git config --global --remove-section https
}
}
Process
{
if($SSID){
Get-SSID | select ssid | foreach-object {
if ($_.ssid -match $SSID){
setProxyConfiguration
} else {
removeProxyConfiguration
}
}
return
}
setProxyConfiguration
}
}