{"id":252,"date":"2019-02-22T05:43:44","date_gmt":"2019-02-22T10:43:44","guid":{"rendered":"http:\/\/itblog.ldlnet.net\/?p=252"},"modified":"2019-02-22T05:45:44","modified_gmt":"2019-02-22T10:45:44","slug":"website-checker-script","status":"publish","type":"post","link":"https:\/\/itblog.ldlnet.net\/index.php\/2019\/02\/22\/website-checker-script\/","title":{"rendered":"Website Availability Checker Script"},"content":{"rendered":"\n<p>We get alerts from time to time that SharePoint and Skype Websites might not be loading correctly or not at all. The following is a script that will generate a report, with time and date, showing the availability of the websites in question and the time it takes to load them.<\/p>\n\n\n\n<p>First off, you want to create a text file called <strong><em>URLList.txt<\/em>&nbsp;<\/strong>that will have the list of websites you want to check. I save the file in the C:\\PowerShell directory but you can change the path to where you need it. If this happens often, having this list prepared will help you evaluate the environment quickly and allow you to troubleshoot if necessary efficiently.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"250\" height=\"189\" src=\"http:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image.png\" alt=\"\" class=\"wp-image-253\"\/><figcaption>URL List Text File<\/figcaption><\/figure><\/div>\n\n\n\n<p>Here is the script:<\/p>\n\n\n<pre class=\"lang:PowerShell\" title=\"WebsiteChecker.ps1\">\n##WebsiteChecker.ps1 built by Lance Lingerfelt - LDLNET LLC - Life In Action! E-Mail: lance.lingerfelt@ldlnet.net - Learn, Do, Live!\n\n## Provide the path to the URL list to test \n$URLListFile = \"c:\\PowerShell\\URLList.txt\"   \n$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue \n  $Result = @() \n  $booltime = 0\n \n##Begin the function cmdlet and define the variables  \n  Foreach ($Uri in $URLList) { \n  $time = try{ \n  $request = $null \n  \n## Request the URL, and measure how long the response took. \n  $result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri -UseDefaultCredentials } \n  $result1.Totalseconds \n  $ResultsTime = $result1.TotalSeconds\n  if($ResultsTime -gt 0)\n    {\n    write-host $uri, $ResultsTime\n    $booltime++\n    write-host $booltime\n    }\n  }  \n  catch \n  { \n\n## If the request generated an exception (i.e.: 500 server error or 404 not found), we can pull the status code from the Exception.Response property \n   $request = $_.Exception.Response \n   $time = -1 \n  }   \n  $result += [PSCustomObject] @{ \n  Time = Get-Date; \n  Uri = $uri; \n  StatusCode = [int] $request.StatusCode; \n  StatusDescription = $request.StatusDescription; \n  ResponseLength = $request.RawContentLength; \n  TimeTaken =  $time;  \n  } \n \n} \n\n##Prepare the output report body in HTML format \n\nif($booltime -gt 0 )\n{\n\nif($result -ne $null) \n{ \n    $Outputreport = \"<HTML><TITLE>Website Availability Report<\/TITLE><BODY background-color:peachpuff><font color =\"\"#99000\"\" face=\"\"Microsoft Table\"\"><H2> Website Availability Report <\/H2><\/font><Table border=1 cellpadding=0 cellspacing=0><TR bgcolor=gray align=center><TD><B>URL<\/B><\/TD><TD><B>StatusCode<\/B><\/TD><TD><B>StatusDescription<\/B><\/TD><TD><B>ResponseLength<\/B><\/TD><TD><B>TimeTaken<\/B><\/TD<\/TR>\" \n    Foreach($Entry in $Result) \n    { \n        if($Entry.StatusCode -ne \"200\") \n        { \n            $Outputreport += \"<TR bgcolor=red>\" \n        } \n        else \n        { \n            $Outputreport += \"<TR>\" \n        } \n        $Outputreport += \"<TD>$($Entry.uri)<\/TD><TD align=center>$($Entry.StatusCode)<\/TD><TD align=center>$($Entry.StatusDescription)<\/TD><TD align=center>$($Entry.ResponseLength)<\/TD><TD align=center>$($Entry.timetaken)<\/TD><\/TR>\" \n    } \n    $Outputreport += \"<\/Table><\/BODY><\/HTML>\" \n} \n$Filename = \"C:\\PowerShell\\URLCheck-\" + [DateTime]::Now.ToString(\"yyyyMMdd-HHmmss\") + \".htm\"\n$Outputreport | out-file $Filename\n\n## Open the file for viewing\nInvoke-Item $Filename\n\n}\n<\/pre>\n\n\n\n<p>Here is your output:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"156\" src=\"http:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image-1.png\" alt=\"\" class=\"wp-image-254\" srcset=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image-1.png 463w, https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image-1-300x101.png 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><figcaption>PowerShell Output<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"252\" src=\"http:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image-2.png\" alt=\"\" class=\"wp-image-255\" srcset=\"https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image-2.png 586w, https:\/\/itblog.ldlnet.net\/wp-content\/uploads\/2019\/02\/image-2-300x129.png 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><figcaption>The report shown in your web browser<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"text-align:center\">HAPPY TROUBLESHOOTING!<br>MAKE THIS SITE BETTER!<br>PLEASE COMMENT!<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>We get alerts from time to time that SharePoint and Skype Websites might not be loading correctly or not at all. The<\/p>\n<p class=\"link-more\"><a class=\"myButt \" href=\"https:\/\/itblog.ldlnet.net\/index.php\/2019\/02\/22\/website-checker-script\/\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3,1,16],"tags":[119,117,8,118,13,116,115,114],"class_list":["post-252","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","category-powershell","category-uncategorized","category-windows","tag-html","tag-invoke-webrequest","tag-powershell","tag-report","tag-script","tag-url","tag-website","tag-website-checker","odd"],"_links":{"self":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":4,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":259,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/posts\/252\/revisions\/259"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itblog.ldlnet.net\/index.php\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}