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'
$site.IISAllowsAnonymous.tostring()
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?