ElegantCode.ComにあるPowerShellスクリプトを修正しようとしています。私はリンクをパラメータとして個別に命名するのではなく、HTTPリンクの大きなテキストファイルを指定するように変更したいと思います。テキストファイルリストからURLの有効性チェックをスクリプト化する
スクリプトがファイルを解析すると、新しいファイルに有効なリンクだけをパイプ処理またはエコーアウトします。
私は最初のハードルに陥っており、入力ファイルをどのようにパラメータとして渡すのか把握できません。スクリプトの
直接リンクはhere
BEGIN {
}
PROCESS {
$url = $_;
$urlIsValid = $false
try
{
$request = [System.Net.WebRequest]::Create($url)
$request.Method = 'HEAD'
$response = $request.GetResponse()
$httpStatus = $response.StatusCode
$urlIsValid = ($httpStatus -eq 'OK')
$tryError = $null
$response.Close()
}
catch [System.Exception] {
$httpStatus = $null
$tryError = $_.Exception
$urlIsValid = $false;
}
$x = new-object Object | `
add-member -membertype NoteProperty -name IsValid -Value $urlIsvalid -PassThru | `
add-member -membertype NoteProperty -name Url -Value $_ -PassThru | `
add-member -membertype NoteProperty -name HttpStatus -Value $httpStatus -PassThru | `
add-member -membertype NoteProperty -name Error -Value $tryError -PassThru
$x
}
}
END {
}
それについての完全なソースコードの任意の最終的な解決策? https://github.com/staxmanade/Scripts/raw/master/Check-Url.ps1が見つかりません – Kiquenet
元のソースはhttps://github.com/staxmanade/Scripts/commits/master/Check-Urlで確認できます.ps1 ...それはhttps://github.com/staxmanade/DevMachineSetup/blob/master/GlobalScripts/Check-Url.ps1に移動されました...私は質問の更新を提出しました。 – adam