Book Image

SharePoint 2013 WCM Advanced Cookbook

By : JOHN CHAPMAN
Book Image

SharePoint 2013 WCM Advanced Cookbook

By: JOHN CHAPMAN

Overview of this book

Table of Contents (19 chapters)
SharePoint 2013 WCM Advanced Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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, anonymous access is most likely not available for that page.

  3. Use the DownloadString method to make a request for the Site contents page on our site:

    $client.DownloadString("http://sharepoint/_layouts/viewlsts.aspx")
    

    If the page is correctly blocked...