Verifying anonymous access to content with PowerShell

In this recipe, we will use PowerShell to ensure that anonymous users can access the home page of our SharePoint site but cannot access the Site contents page.

How to do it…

Follow these steps to verify the anonymous access to content with PowerShell:

  1. Create a new WebClient object. We are using the WebClient object to make simple, unauthenticated web requests against our SharePoint site.
    $client = New-Object System.Net.WebClient
    
  2. Use the DownloadString method to make a request for the home page of our site as follows:
    $client.DownloadString("http://sharepoint")
    

    If we receive the HTML content for our page, our request was successful. However, if we receive an exception with a 401 or 403 HTTP response, ...

Get SharePoint 2013 WCM Advanced Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.