Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Enable Anonymous Access in SharePoint using PowerShell

$
0
0
In continuation with my last post, How to Enable Anonymous Access in SharePoint 2013, Here are some nifty PowerShell scripts to manage anonymous access in SharePoint:

PowerShell script to Enable Anonymous Access settings of a Web Application:
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$webApp = Get-SPWebApplication 'http://sharepoint.crescent.com/'
$webApp.IisSettings['Default'].AllowAnonymous=$true
$webApp.update()

PowerShell to Set anonymous access on specific SharePoint sites:
$web = Get-SPWeb http://sharepoint.crescent.com/sites/operations
#Enabled - lists and libraries; On - Entire web site ; Disabled - Self explanatory :-)
$web.AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::Enabled
$web.Update()

Enable anonymous access on all sites under a web application:
(Get-SPWebApplication http://sharepoint.crescent.com | Get-SPSite | Get-SPWeb | Where {$_ -ne $null -and $_.HasUniqueRoleAssignments -eq $true } ) | ForEach-Object { $_.AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::On; $_.Update(); }

Enable Disable anonymous access at List or library level in SharePoint 2010:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$web = Get-SPWeb http://sharepoint.crescent.com/sites/operations

$list = $web.lists.tryGetList("Documents")
if($list -ne $null)
{
$list.BreakRoleInheritance($true)
$list.AllowEveryoneViewItems = $true
$list.AnonymousPermMask64 ="Open, OpenItems, ViewListItems, ViewVersions, ViewFormPages, ViewPages, UseClientIntegration"
$list.update();
}
To disable anonymous access, You can either set the Permission mask as:
$list.AnonymousPermMask64 ="EmptyMask" or reset inheritance by calling: $list.ResetRoleInheritance() 

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>