İçeriğe geç
Guides 2 dk okuma 729 görüntülenme

Using Proxies in PowerShell

Working with proxies in PowerShell: Invoke-WebRequest, System.Net.WebProxy, system proxy configuration, and automation via scripts.

Using Proxies in PowerShell

Using Proxies in PowerShell

Proxies in PowerShell

PowerShell is a powerful automation tool in Windows. Working with proxies is crucial for scripts operating in corporate networks or requiring anonymity.

Invoke-WebRequest with Proxies

Basic Request via Proxy

$proxy = "http://proxy_ip:8080"
$response = Invoke-WebRequest -Uri "https://httpbin.org/ip" -Proxy $proxy
$response.Content

With Authentication

$proxy = "http://proxy_ip:8080"
$proxyCred = New-Object System.Management.Automation.PSCredential(
    "username",
    (ConvertTo-SecureString "password" -AsPlainText -Force)
)

$response = Invoke-WebRequest -Uri "https://httpbin.org/ip" `
    -Proxy $proxy `
    -ProxyCredential $proxyCred

$response.Content

Invoke-RestMethod (for JSON API)

$proxy = "http://proxy_ip:8080"
$result = Invoke-RestMethod -Uri "https://httpbin.org/ip" -Proxy $proxy
$result.origin  # your IP via proxy

System.Net.WebProxy

Programmatic Configuration

$webProxy = New-Object System.Net.WebProxy("http://proxy_ip:8080", $true)
$webProxy.Credentials = New-Object System.Net.NetworkCredential("user", "pass")

# Apply to WebClient
$client = New-Object System.Net.WebClient
$client.Proxy = $webProxy
$result = $client.DownloadString("https://httpbin.org/ip")
Write-Host $result

Bypassing Proxy for Specific Addresses

$webProxy = New-Object System.Net.WebProxy("http://proxy_ip:8080", $true)
$webProxy.BypassList = @("localhost", "*.local", "192.168.*")
$webProxy.BypassProxyOnLocal = $true

HttpClient (.NET)

For advanced scenarios, use the .NET HttpClient:

$proxy = New-Object System.Net.WebProxy("http://proxy_ip:8080")
$proxy.Credentials = New-Object System.Net.NetworkCredential("user", "pass")

$handler = New-Object System.Net.Http.HttpClientHandler
$handler.Proxy = $proxy
$handler.UseProxy = $true

$client = New-Object System.Net.Http.HttpClient($handler)
$response = $client.GetStringAsync("https://httpbin.org/ip").Result
Write-Host $response

System Proxy

Reading Current Settings

# From Windows Registry
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$proxyEnabled = (Get-ItemProperty -Path $regPath).ProxyEnable
$proxyServer = (Get-ItemProperty -Path $regPath).ProxyServer
Write-Host "Proxy enabled: $proxyEnabled"
Write-Host "Proxy server: $proxyServer"

Setting System Proxy

$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"

# Enable proxy
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 1
Set-ItemProperty -Path $regPath -Name ProxyServer -Value "proxy_ip:8080"

# Exceptions
Set-ItemProperty -Path $regPath -Name ProxyOverride -Value "localhost;*.local"

Write-Host "Proxy configured"

Disabling System Proxy

Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0
Write-Host "Proxy disabled"

Environment Variables

Setting

$env:HTTP_PROXY = "http://proxy_ip:8080"
$env:HTTPS_PROXY = "http://proxy_ip:8080"
$env:NO_PROXY = "localhost,*.local"

Persistent Setting

[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://proxy_ip:8080", "User")
[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://proxy_ip:8080", "User")

Verification

Write-Host "HTTP_PROXY: $env:HTTP_PROXY"
Write-Host "HTTPS_PROXY: $env:HTTPS_PROXY"

Proxy Rotation in Scripts

$proxies = @(
    "http://user:pass@proxy1:8080",
    "http://user:pass@proxy2:8080",
    "http://user:pass@proxy3:8080"
)

$urls = @(
    "https://httpbin.org/ip",
    "https://httpbin.org/headers",
    "https://httpbin.org/user-agent"
)

foreach ($url in $urls) {
    $proxy = $proxies | Get-Random
    try {
        $response = Invoke-RestMethod -Uri $url -Proxy $proxy -TimeoutSec 10
        Write-Host "OK: $url via $proxy"
        Write-Host $response
    } catch {
        Write-Host "FAIL: $url via $proxy - $($_.Exception.Message)"
    }
}

Proxy Testing

function Test-Proxy {
    param(
        [string]$ProxyServer,
        [string]$ProxyPort,
        [string]$Username,
        [string]$Password
    )

    $proxy = "http://${ProxyServer}:${ProxyPort}"
    $cred = $null

    if ($Username) {
        $cred = New-Object System.Management.Automation.PSCredential(
            $Username,
            (ConvertTo-SecureString $Password -AsPlainText -Force)
        )
    }

    try {
        $params = @{
            Uri = "https://httpbin.org/ip"
            Proxy = $proxy
            TimeoutSec = 10
        }
        if ($cred) { $params.ProxyCredential = $cred }

        $response = Invoke-RestMethod @params
        Write-Host "OK - IP: $($response.origin)" -ForegroundColor Green
        return $true
    } catch {
        Write-Host "FAIL - $($_.Exception.Message)" -ForegroundColor Red
        return $false
    }
}

# Usage
Test-Proxy -ProxyServer "proxy_ip" -ProxyPort "8080" -Username "user" -Password "pass"

Bulk Proxy Testing

$proxyList = Get-Content "proxies.txt"  # format: ip:port:user:pass

$results = foreach ($line in $proxyList) {
    $parts = $line.Split(":")
    $ip = $parts[0]; $port = $parts[1]
    $user = $parts[2]; $pass = $parts[3]

    $proxy = "http://${ip}:${port}"
    try {
        $cred = New-Object PSCredential($user, (ConvertTo-SecureString $pass -AsPlainText -Force))
        $resp = Invoke-RestMethod "https://httpbin.org/ip" -Proxy $proxy -ProxyCredential $cred -TimeoutSec 5
        [PSCustomObject]@{Proxy=$line; Status="OK"; IP=$resp.origin}
    } catch {
        [PSCustomObject]@{Proxy=$line; Status="FAIL"; IP="N/A"}
    }
}

$results | Format-Table -AutoSize
$results | Export-Csv "proxy_check_results.csv" -NoTypeInformation

Conclusion

PowerShell provides flexible tools for working with proxies: from simple cmdlets (Invoke-WebRequest) to the full .NET API. The ability to manage system proxies via the registry and environment variables makes PowerShell ideal for automating proxy configuration on Windows machines.

Güncellendi: 06.03.2026
Kategoriye dön

Bunları da okuyun

Guides 2 dk

Nike SNKRS için Proxy: Sınırlı Sürümler ve Çoklu Katılım

Nike SNKRS'ta birden fazla hesapla çekilişlere katılmak, IP limitlerini aşmak ve ban yemeden sınırlı sürümleri kapmak için residential veya mobil proxy kullanın. Hangi türü seçmeli ve nasıl kurmalı.

Guides 2 dk

iPhone'da Proxy Nasıl Kurulur (Wi-Fi ve SOCKS5)

iPhone'da proxy'yi yerleşik Wi-Fi ayarlarından (HTTP/HTTPS) veya SOCKS5 ile hücresel kapsama için Shadowrocket gibi bir uygulamayla kurun. Adım adım iOS kurulumu ve bilinmesi gereken kısıtlar.

Guides 3 dk

Tinder için proxy: çoklu hesap ve ban'lerden kaçınma

Birden fazla profil işletmek ve IP shadowban'lerinden kaçınmak için Tinder'da mobil veya residential proxy kullanın. Mobilin neden kazandığı, kurulumu ve proxy'nin şehri neden değiştirmediği.

Guides 2 dk

StockX için proxy: fiyat takibi ve hesap yönetimi

StockX'te fiyatları izlemek, birden fazla hesap çalıştırmak ve drop'ları yasaklanmadan kapmak için residential, ISP veya mobil proxy kullanın. Hangi türü seçeceğinizi ve nasıl kuracağınızı anlatıyoruz.

Guides 3 dk

OpenAI API için Proxy: Erişim, Hız Limitleri ve Kurulum

OpenAI API'yi residential veya ISP proxy üzerinden yönlendirerek desteklenen bölgelere erişin, 429 hız limitlerinden kaçının ve hesapları izole edin. Hangi proxy'yi seçmeli ve Python kurulum örnekleri.

Guides 1 dk

E2E testleri için Cypress'te proxy kurulumu

Cypress'te proxy kurulumu: HTTP_PROXY değişkenleri, cy-proxy-middleware ve coğrafi konuma bağlı içeriğin test edilmesi.

Proxy'lerimizi deneyin

100+ ülkede 20,000+ proxy

support_agent
GProxy Support
Usually replies within minutes
Hi there!
Send us a message and we'll reply as soon as possible.