I need to set permissions on a lot of SharePoint folders in a document library but I don't want to have to spin through all folders
to find the specific one each time. I have to set permissions on about 1000 folders and have an XML document where I'm getting the folders and their permissions from.
I have the script about 90% written using a CAML query to get the specific folder. (This works fine and returns the specific folder I'm looking for
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.Query = "<OrderBy>
<FieldRef Name=BaseName Ascending=TRUE></FieldRef>
<Eq><FieldRef Name=ContentType/><Value Type=Text>Folder</Value></Eq>
<Eq><FieldRef Name=BaseName/><Value Type=Text>$folderName</Value></Eq>
$spQuery.ViewAttributes = "Scope=RecursiveAll"
$spListItems = $spList.GetItems($spQuery)
However, when I try to set the $currentFolder, it is an SPFolder instead of SPItem.
foreach ($spListItem in $spListItems)
$currentItem = $spListItem.Name
$folderName = $spListItem.Folder.URL
$folderName = $folderName.Replace($currentItem,"")
$RelativeFolderURL = $spListItem.URL
And the method to break inheritance and set permissions is only available on an SPItem object
[Microsoft.SharePoint.SPGroupCollection]$spgroups = $web.SiteGroups
[Microsoft.SharePoint.SPGroup]$spgroup = $spgroups[$groupName]
[b][u]#The Next Line Breaks[/u][/b]
[b][u]#This Line Doesn't Work Either[/u][/b]
Write-Host "Permission provided for group ", $groupName
I've attached 2 files.
One that works when I explicitly give it a folder name.
The second is my script that I'm trying to use CAML to get the folder name
I'm hoping someone here will be able to help figure this out.