Hello,
I have a business case need for a web analytics company. They need to test 100’s of URLs, which is pretty easy I guess, but they need to test them FROM their SharePoint online team site so the testing traffic can be filtered out by the web analytics tool.
I currently cobbled a script together from Googling (i.e. copy and paste from others) which first connects to their SharePoint Online, and then uses Invoke-WebRequest to each URI from a text file.
My question is, how can I be sure that the script is working as intended - that it’s actually doing the WebRequests from the SharePoint site and not from their computer? I know they can check on the website side, but I was wondering if there’s anything I can do in the script to get the origin of the WebRequest…
Below is the script and I left in the persons name up top, as he was the original author. Thank you.
P.S. - there are some lines cut off at the end that finish and export and open and HTML file.
##############################################################################
##
## Website Availability Monitoring
## Created by Sravan Kumar S
## Date : 19 Apr 2013
## Version : 1.0
## Email: sravankumar.s@outlook.com
############################################################################ Connect to SharePoint Online
$pass = cat C:\UrlTest\365securestring.txt | convertto-securestring
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "admin@lgsmarketingservices.com",$pass
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService –Url https://mySPdomain-admin.sharepoint.com -credential $mycred
## The URI list to test
$URLListFile = "c:\UrlTest\URLList.txt"
$URLList = Get-Content $URLListFile -ErrorAction SilentlyContinue
$Result = @()
Foreach($Uri in $URLList) {
$time = try{
$request = $null
## Request the URI, and measure how long the response took.
$result1 = Measure-Command { $request = Invoke-WebRequest -Uri $uri }
$result1.TotalMilliseconds
}
catch
{
$request = $_.Exception.Response
$time = -1
}
$result += [PSCustomObject] @{
Time = Get-Date;
Uri = $uri;
StatusCode = [int] $request.StatusCode;
StatusDescription = $request.StatusDescription;
ResponseLength = $request.RawContentLength;
TimeTaken = $time;
}
}
#Prepare email body in HTML format
if($result -ne $null)
{
$Outputreport = "Website Availability Report Website Availability Report URLStatusCodeStatusDescriptionResponseLengthTimeTaken</TD"
Foreach($Entry in $Result)
{
if($Entry.StatusCode -ne "200")
{
$Outputreport += ""
}
else
{
$Outputreport += ""
}
$Outputreport += "$($Entry.uri)$($Entry.StatusCode)$($Entry.StatusDescription)$($Entry.ResponseLength)$($Entry.timetaken)"
}
$Outputreport += ""
}
$Outputreport | out-file C:\UrlTest\UrlTest.htm
Invoke-Expression C:\UrlTest\UrlTest.htm