powershell SharePoint通过PowerShell添加用户和中断角色继承

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell SharePoint通过PowerShell添加用户和中断角色继承相关的知识,希望对你有一定的参考价值。

# --------Input Parameters 
$userName="scu\SP-MSBAnnouncementsMembers"
$siteURL="http://thesound/Dept/MBS"
$listName="Announcements"
$site=Get-SPSite  $ siteURL
$web=$site.RootWeb
$list=$web.lists[$listName]
$collRoleDefinitions = $web.RoleDefinitions;
$collRoleAssignments = $list.RoleAssignments;
$user=$web.EnsureUser($userName);
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($user.LoginName, $user.Email, $user.Name, $user.Notes);
$collRoleDefinitionBindings = $roleAssignment.RoleDefinitionBindings;
$collRoleDefinitionBindings.Add($collRoleDefinitions["Contribute"]);
$collRoleAssignments.Add($roleAssignment);
$list.Update(); 
Add-PSSnapin Microsoft.SharePoint.Powershell

$web = Get-SPWeb http://portal.opwftg.com/sites/OPWSS/Teams/OPCO/OES
$account = $web.EnsureUser("opwftg\cin-all")
$role = $web.RoleDefinitions["Contribute"]

$list = $web.Lists["Customer Compalint Doc Library"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()

$list = $web.Lists["Customer Complaint Links"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()

$list = $web.Lists["Deviations"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()

$list = $web.Lists["RMA"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()

$web.Dispose()
Add-PSSnapin Microsoft.SharePoint.Powershell

$web = Get-SPWeb http://portal.opwftg.com/sites/OPWSS/Teams/OPCO/OES
$account = $web.EnsureUser("opwftg\cin-all")
$role = $web.RoleDefinitions["Contribute"]

$list = $web.Lists["Customer Complaint Anouncements"]

$list.BreakRoleInheritance($true)

$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)

$list.Update()
$web.Dispose()

以上是关于powershell SharePoint通过PowerShell添加用户和中断角色继承的主要内容,如果未能解决你的问题,请参考以下文章

通过PowerShell卸载全部的SharePoint 2010 解决方式

powershell 通过PowerShell计算SharePoint列表中所有项目的版本。

powershell 将用户添加到sharepoint站点,并通过powershell为该用户分配角色

通过Powershell添加和安装SharePoint 2010解决方案

通过Powershell收回并卸载SharePoint解决方案

使用 Powershell 插入 Sharepoint 凭据