This post was most recently updated on September 30th, 2022.
2 min read.This post is about managing Anonymous Access on a SharePoint site (SPWeb) using PowerShell commandlets. It’s often a lot more feasible and even easier than using the browser interface! In some cases, it’s borderline impossible to avoid it anyway – since accessing the GUI switch might not be possible.
Description
Assume you have a site collection that you have published to the whole world. You’ll have anonymous access enabled at both web application and site collection levels, and configured permissions at the root web-level. Now, let’s assume that you want to disable anonymous access on a certain site deeper in the site structure. This way anonymous users could access your site at http://site.com and http://site.com/subsite, but not at http://site.com/subsite/deepsubsite. As an added bonus, you get security trimming! That means, that the web would even be removed from the navigation for any users, who cannot access it. Especially anonymous users!
Sounds pretty great. How to achieve this, though?
Solution: Modify Anonymous Access using PowerShell
Of course, you could do this through the site permissions page via browser (http://site.com/_layouts/15/user.aspx) by breaking permissions inheritance and disabling anonymous access, but there are multiple situations when this is not feasible – say, for example, that you already have a redirection for that certain URL set in the IIS or gateway, and can’t access the page.
Luckily, you can also change the permissions using PowerShell. See below!
$web = Get-SPWeb http://site.com/subsite/deepsubsite
$web.BreakRoleInheritance($true)
# On - Entire web site
# Enabled - lists and libraries
# Disabled - Well... Yeah.
$web.AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::Disabled
$web.Update()
This is a lot faster than through a browser, right? :)
Just remember to use the right URL for the web, SharePoint will find out the right zone for you!
- Join my session at CTTT25 this week: Level Up Your Teams Extensibility Game with Blazor | Session materials from Cloud Technology Townhall Tallinn 2025! - January 28, 2025
- How to identify which wifi band your Decos are using? - January 21, 2025
- Don’t assign root domain to GitHub Pages if you use it for email! - January 14, 2025