Proxy対応

  • 以下でProxy越えができた
    PS > $Creds=Get-Credential
    
    PowerShell credential request
    Enter your credentials.
    User: [ユーザ名]
    Password for user [ユーザ名]: [パスワード]
    
    PS > $Wcl=New-Object System.Net.WebClient
    PS > $Wcl.Proxy.Credentials=$Creds
    PS > Invoke-WebRequest http://wiki.examind.net

スクリプトで使うには

  • 事前にパスワードファイルを生成
    $tmpCred = Get-Credential 
    $tmpCred.Password | ConvertFrom-SecureString | Set-Content "pwd.dat"
  • パスワードファイルを使ってプロキシ設定
    PS > $password = Get-Content "pwd.dat" | ConvertTo-SecureString
    PS > $credential = New-Object System.Management.Automation.PsCredential "[ユーザ名]", $password
    PS > $wc = New-Object System.Net.WebClient
    PS > $wc.Proxy.Credentials = $credential
    
  • 後はアクセスするだけ
    PS > Invoke-WebRequest http://wiki.examind.net

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-02-03 (水) 15:29:07 (1178d)