Turn on anonymous access in SharePoint2010 web application using PowerShell
-
06-12-2019 - |
Question
I try to use the Set-SPWebApplication to turn on anonymous access in SharePoint2010 web application using PowerShell, however it give me the following error (see the screenshot here):
Add SharePoint snappin
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$app = Get-SPWebApplication http://ybbest/ Set-SPwebApplication -Identity $app -AllowAnonymousAccess:$True -Zone Default
Set-SPWebApplication : A parameter cannot be found that matches parameter name 'AllowAnonymousAccess'. At C:\Users\Administrator\AppData\Local\Temp\1\5fa9c881-a962-44fa-8edc-4b5e4c4bb8d1.ps1:6 char:59 + Set-SPwebApplication -Identity $app -AllowAnonymousAccess: <<<< $True -Zone Default + CategoryInfo : InvalidArgument: (:) [Set-SPWebApplication], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.SharePoint.PowerShell.SPCmdletSetWebApplication
Solution
PowerShell errors can be deceptive, but for once this one is quite clear: That switch parameter only exists for new-SPWebApplication
not set-SPWebApplication
hence the error.
You can set it afterwards too, but then you need to get an instance of the SPWindowsAuthenticationProvider
Remember to also set AnonymousState for each SPSite that must run anonymously.
More info and script samples here.