0
0

More than 1 year has passed since last update.

PowerShell で PAC ファイルを使ったプロキシ設定をしてみた

Posted at

前提

  • Windows OS のインストール直後、または、仮想マシンを起動した直後であることとする。
  • PowerShell は管理者モードで起動していることとする。

1. バージョン情報

1.1. Windows OS Version

PS C:\Users\Administrator> (Get-CimInstance -ClassName Win32_OperatingSystem).Version
10.0.19045
PS C:\Users\Administrator>

1.2. PowerShell Version

PS C:\Users\Administrator> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
PS C:\Users\Administrator>

2. 事前確認

2.1. プロキシ設定の自動読み込み設定

  • 何も出力されないことが正。
PS C:\Users\Administrator> (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings")."AutoDetect"
PS C:\Users\Administrator>

2.2. プロキシ設定の PAC ファイル読み込み

  • 何も出力されないことが正。
PS C:\Users\Administrator> (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings")."AutoConfigURL"
PS C:\Users\Administrator>

3. PAC ファイルを使ったプロキシ設定

$pac = "http://XXX.XX.X.XX/proxy.pac"
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "AutoDetect" -Value "0" -Type DWORD -Force
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name "AutoConfigURL" -Value $pac -Type STRING -Force

4. 事後確認

4.1. プロキシ設定の自動読み込み設定

PS C:\Users\Administrator> (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings")."AutoDetect"
0
PS C:\Users\Administrator>

2.2. プロキシ設定の PAC ファイル読み込み

PS C:\Users\Administrator> (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings")."AutoConfigURL"
http://XXX.XX.X.XX/proxy.pac
PS C:\Users\Administrator>

2.3. HTTP ステータスコード取得による動作確認

  • Windows OS のインストール直後、または、仮想マシンを起動した直後であるとき、HTTP ステータスコード取得には、InternetExplorer のプロファイルが必要となる。
  • ここでは、Web ブラウザのプロファイルを作成するために、InternetExplorer のプロセスだけを起動させる。
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible=$false
$ie.Quit()
try {
  $response = Invoke-WebRequest -Uri "http://hogehoge.com/"
} catch {
  $response = $_.Exception.Response
}
$StatusCode = $response.StatusCode
$StatusDescription = $response.StatusDescription
Write-Host "$StatusCode $StatusDescription"

200 OK
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0