We take an example of an application directly:
Add the "read-only" permission for "Domain\lixs" to the "Trade unions" folder in the departmental Shared Documents library.
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/5c/24/wkiol1ubpnbzn_jaaaevmhx8mzw420.jpg "height=" 359 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/5c/24/wkiol1ubpnmckbjbaagtsyuwij0464.jpg "height=" 378 "/>
650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m01/5c/29/wkiom1ubptyrcwb-aaet9wbsfn0672.jpg "height=" 364 "/>
Code content:
############################################ #Author:lixiaosong#email:[email protected]; [email protected] #For: Set permissions for SharePoint library folders Security group #version:1.0 2015 March 26 ################################## ########### #function add-sppermissiontosegroup { param ( [parameter (mandatory= $True, position=1)] [string] $SPWeb, [parameter (mandatory= $True, position=2)] [string] $SPList, [parameter (mandatory= $True, position=3)] [string] $ADUser, [parameter (Mandatory=$ true,position=4)] [string] $SPFolder, [parameter ( mandatory= $True, position=5)] [string] $SPPermission) add-pssnapin Microsoft.sharepoint.powershell#http://glproject/pmo/doc$web = get-spweb "$SPWeb" function grantuserpermission ($userName) { [ Microsoft.SharePoint.SPUserCollection] $web $spusers =[microsoft.sharepoint.spusercollection]. Siteusers [microsoft.sharepoint.spuser] $spuser = $spusers [$userName] $sproleass =new-object microsoft.sharepoint.sproleassignment ([Microsoft.SharePoint.SPPrincipal] $spuser) $folder. Breakroleinheritance ("true") $sproleass. Roledefinitionbindings.add ($web. roledefinitions["$SPPermission"]) $folder. Roleassignments.add ($sproleass); write-host "permission provided for user ", $userName } $doclib =[microsoft.sharepoint.spdocumentlibrary] $web. lists["$SPlist"] $foldercoll = $doclib. Folders; foreach ($folder in $foldercoll) { Write-Host $folder. Name if ($folder. Name.equals ("$SPFolder")) { grantuserpermission ("Domain\ $ADUser ") } } Write-Host " completed ... " $web. Close ()}
This article is from the "operation and maintenance of life" blog, please make sure to keep this source http://lixiaosong.blog.51cto.com/705126/1627346
To set the SharePoint Site Library folder security Group or AD user Rights script