by rkadwad at 2013-03-25 23:02:51
Hi ALl,by mjolinor at 2013-03-26 05:33:14
I have below script which check the URL and send the Mail if its down. Here i want to save the output to notepad when each time it run. Can anybody please help.
function siteupdown{
## Display Help
if (($Args[0] -eq "-?") -or ($Args[0] -eq "-help")) {
""
"Usage: SysinternalsSiteTest.ps1 -alert
<address> -log"
" -alert
<address> Send e-mail alerts"
" -log Log results"
""
"Example: SysinternalsSiteTest.ps1 -alert somebody@nospam.com -log"
""
exit
}
## Create the variables
$global:GArgs = $Args
$urlsToTest = @{}
$urlsToTest["SP2010"] = "http://sp2010/Pages/default.aspx"
## Add more URLs for monidoting **Note URL cannot be rediriecting urls.
#$urlsToTest["TechNet Redirect"] = "http://www.microsoft.com/sysinternals"
#$urlsToTest["Sysinternals Home"] = "http://www.microsoft.com/technet/sysinternals/default.mspx"
#$urlsToTest["Sysinternals Forum"] = "http://forum.sysinternals.com"
#$urlsToTest["Sysinternals Blog"] = "Microsoft Learn: Build skills that open doors in your career
#$urlsToTest["Sysinternals Downloads"] = "http://download.sysinternals.com/Files/NtfsInfo.zip"
$successCriteria = @{}
$successCriteria["SP2010"] = "press releases"
## Add more success criteria here.
#$successCriteria["TechNet Redirect"] = "Mark Russinovich"
#$successCriteria["Sysinternals Home"] = "Mark Russinovich"
#$successCriteria["Sysinternals Forum"] = "Sysinternals Utilities"
#$successCriteria["Sysinternals Blog"] = "Sysinternals Site Discussion"
#$successCriteria["Sysinternals Downloads"] = "ntfsinfo.exe"
## Set Username Password and domain here
$Username = ‘be’
$Password = ‘password!!!1’
$Domain = ‘gen’
## sets up the call
$webClient = new-object System.Net.WebClient
$webClient.credentials = New-Object System.Net.NetworkCredential($Username, $Password, $Domain)
foreach ($key in $urlsToTest.Keys) {
$alert = $false
$output = ""
$startTime = get-date
$output = $webClient.DownloadString($urlsToTest[$key])
$endTime = get-date
if ($output -like $successCriteria[$key]) {
$key + "t
tSuccesst
t" + $startTime.DateTime + "t
t" + ($endTime - $startTime).TotalSeconds + " seconds"
if ($GArgs -eq "-log") {
$key + "t
tSuccesst
t" + $startTime.DateTime + "t
t" + ($endTime - $startTime).TotalSeconds + " seconds" >> WebSiteTest.log
}
} else {
$key + "t
tFailt
t" + $startTime.DateTime + "t
t" + ($endTime - $startTime).TotalSeconds + " seconds"
$alert = $true
if ($GArgs -eq "-log") {
$key + "t
tFailt
t" + $startTime.DateTime + "t
t" + ($endTime - $startTime).TotalSeconds + " seconds" >> WebSiteTest.log
$alert = $true
}
if ($alert -eq $true) {
Write-Host "Sending Email"
## Set email settings Below. $emailFrom, $EmailTo, $smtpServer
$emailFrom = "email@nospam.com"
$emailTo = "email@nospam.com"
$subject = "URL Test Failure - " + $startTime
$body = "URL Test Failure: " + $key + " (" + $urlsToTest[$key] + ") at " + $startTime
$smtpServer = "smtp.nospam.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom,$emailTo,$subject,$body)
}
}
}
}
## Makes the script run forever.
$i=1
for ($i -le 5; $i++)
{
## Change the number, to change check site interval. 1 = 1 seconds, 30 = 30 seconds, etc…
sleep 30;
siteupdown}
</address></address>
The question is a little ambiguous. Are you wanting to save the ouput from the website, or the output from the script?by rkadwad at 2013-03-26 09:43:06
If you’re wanting to save the output from the script, and are doing write-host, then you probably should look at start-transcript.
HI,by mjolinor at 2013-03-26 11:38:53
I want to save the output from the script. It should record the output when each time script runs without overwritten. As i am newbie to this world could you please post me the script which can do the above said operation with below script
run this:
get-help start-transcript -full
Read everything it displays, and then see if you can incorporate that information into the script.
Let me know if you cannot figure out how to make that work.
I believe you’ll find it’s not as difficult as you’re imagining.