Testing URLs from a SharePoint Online site?

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Yuan Li Yuan Li 9 months, 3 weeks ago.

  • Author
    Posts
  • #35276
    Profile photo of Scott Bunting
    Scott Bunting
    Participant

    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
  • #35281
    Profile photo of Yuan Li
    Yuan Li
    Participant

    After the connecting to sharepoint code, can you add something like

    if ($? -eq $true){

    # Test URI
    }
    else{

    write-error "Connection failed"

    }

You must be logged in to reply to this topic.