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이 알아 내야 할 것인가. 어떤 제안?
감사
안녕하세요. 귀하의 의견을 보내 주셔서 감사합니다. 나는이 모든 것에 대해 상당히 새로운 것이므로 실제로 스크립트를 편집하여 그 작업을 수행하는 방법을 모르겠습니다. 사과. – jakeythehobo
실제로 CSV 파일에 헤더를 포함 할 필요는 없습니다. 커스텀 인수를'-Header' 인수로'Import-Csv'에 사용할 수 있습니다. – Joey
@ 조이 덕분에 나는 결코 알지 못했습니다 –