使用 PowerShell 在 SharePoint 中启用匿名访问
如何使用 PowerShell 在 SharePoint 中启用匿名访问?
在 SharePoint 中启用匿名访问允许未登录系统的用户查看内容并与之交互。继续我的上一篇文章,如何在 SharePoint 2013 中启用匿名访问?在这篇博文中,我们将向您展示如何使用 PowerShell 在 SharePoint 中启用匿名访问。以下是一些用于管理 SharePoint 中的匿名访问的漂亮 PowerShell 脚本:
在 SharePoint 中启用匿名访问涉及三个步骤:
- 启用 SharePoint Web 应用程序的匿名访问
- 启用对 SharePoint 网站的匿名访问
- 打开对列表和库的匿名访问
PowerShell 启用 Web 应用程序的匿名访问设置:
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$webApp = Get-SPWebApplication 'https://sharepoint.crescent.com/'
$webApp.IisSettings['Default'].AllowAnonymous=$true
$webApp.update()
PowerShell 在特定 SharePoint 网站上设置匿名访问:
$web = Get-SPWeb https://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()
在网络应用程序下的所有网站上启用匿名访问:
(Get-SPWebApplication https://sharepoint.crescent.com | Get-SPSite | Get-SPWeb | Where {$_ -ne $null -and $_.HasUniqueRoleAssignments -eq $true } ) | ForEach-Object { $_.AnonymousState = [Microsoft.SharePoint.SPWeb+WebAnonymousState]::On; $_.Update(); }
在 SharePoint 2013/2016 中启用禁用列表或库级别的匿名访问:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the web and list
$web = Get-SPWeb https://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();
}
要禁用匿名访问,您可以将权限掩码设置为: $list.AnonymousPermMask64 =”EmptyMask” 或通过调用重置继承: $list.ResetRoleInheritance()
