I need to create a PowerShell script that will disable anonymous access to the given SharePoint web application.

However, I have thus far been unsuccessful.

All scripts have been run under the "SharePoint 2013 Management Shell" as administrator.

The most recent attempt, I tried setting AllowAnonymous to false. And when I look at the properties from powershell, it indeed shows false immediately after setting it. However, the setting never applies, as evidenced by examining the web application in Central Administration. I thought maybe I needed to call update() but PowerShell tells me that it doesn't exist.

$webApp = Get-SPWebApplication 'http://someurl:9999'
$auth = Get-SPAuthenticationProvider -WebApplication $webApp -Zone 'Default' -Identity Windows
$auth.AllowAnonymous = $false

Additional Info

Interestingly enough, the following appears to reliably tell me if anonymous access is enabled corresponding to Enable anonymous access under "Central Administration" -> "Manage Web Applications" -> (select site) -> "Authentication Providers" -> (select Default Zone)

$site = Get-SPSite 'http://someurl:9999'

However, not only does the property appear to be misnamed (because in IIS itself, anonymous access is enabled for all the test sites, as SharePoint set it up), but the property is readonly.

How can I disable anonymous access to a SharePoint Web Application from PowerShell?

2 Answers 2


It appears to live under the IisSettings of the web app.

This is what worked for me (you can replace 'Default' with any other zone name that is mapped)

$webApp = Get-SPWebApplication 'http://someurl:9999'

As I understand it, you can't revert anonymous access on the SPAuthenticationProvider instance, you need to create a new one. By default, the AllowAnonymous switch is false, meaning you shouldn't specify it upon creation:

$authenticationProvider = New-SPAuthenticationProvider

Runnning this will set the AllowAnonymous switch to false:

enter image description here

When you have your new authentication provider, set the web application to use that one instead - like this:

$authenticationProvider = New-SPAuthenticationProvider 
Set-SPWebApplication http://someurl:9999 -Zone Default -AuthenticationProvider $authenticationProvider
  • I tried your suggestion, but Central Administration still shows Enable anonymous access as checked. I am viewing this under "Central Administration" -> "Manage Web Applications" -> (select site) -> "Authentication Providers" -> (select Default Zone)
    – Nathan
    Aug 7, 2013 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.