1
URLを監視するスクリプトを作成しようとしています。私は、私が欲しい情報を得ることができた、とこのPowerShellで変数出力の名前を変更する
$logfile = "C:\LogFileTest.log"
Function WriteHeader-Websites {
[cmdletbinding()]
param (
[string]$URL
)
if ($logfile -eq "nologfile"){
write-host
write-host "$URL"
write-host
}
else {
add-content -path $logfile -value ""
add-content -path $logfile -value "$URL"
add-content -path $logfile -value ""
}
}
Function Test-Websites {
$URLs = Get-Content -Path C:\WebsiteChecks.txt
foreach ($URL in $URLs) {
$ArrayLine =$Line.split(",")
$
$Line.name =
try {
$request = [System.Net.WebRequest]::Create($URL)
$response = $request.GetResponse()
WriteHeader-Websites "$URL is available!"
} catch {
WriteHeader-Websites ("$URL failed! The error message was '{0}'." -f $_)
} finally {
if ($response) {
$response.Close()
Remove-Variable response
}
}
}
}
Test-Websites
私のテキストファイルは次のようになりますように私のスクリプトに見えます:
http://www.google.com
http://www.bing.com
http://www.bbc.co.uk
、スクリプトからの出力は次のようになります。
http://www.google.com is available!
ウェブサイトの短い名前をテキストファイルに追加して、代わりにその名前を使用したいと考えています。
テキストファイルの例は次のようになります。
http://www.google.com,Google Website
http://www.bing.com,Bing Website
と私はリターンがどのように見えるしたいと思います:
Google Website is available!
Bing Website is available!
または
Google Website failed! Error message is...
しかし、私はありません持っていますそれをどうやって行うのか、Googleがそれを見つけ出すにはどうすればいいのだろうか。助言がありますか?
おかげ
こんにちはDavid。あなたのご意見ありがとうございます。私はこれにかなり新しいので、実際にスクリプトを編集してその作業を行う方法がわからないのですか?謝罪。 – jakeythehobo
実際にCSVファイルにヘッダーを含める必要はありません。 'Import-Csv'の' -Header'引数でカスタムのものを使うことができます。 – Joey
@ジョーのおかげで私はそれを知らなかった –