简体   繁体   中英

Check permissions in files/documents within document sets

I am attempting to traverse through a document set in a documen library and list out files/documents if they have "unique permissions" set. I have the followin script so far but for some reason the check is not working/bringing back the expected results:

$siteURL = new-object  
Microsoft.SharePoint.SPSite("https://test.code/sites/ITTest")

$web = $siteURL.rootweb

#Getting the required document library
$libraryName = $web.Lists["FurtherTests"]
$rootFolder = $libraryName.RootFolder

#Iterating through the required documents sets
foreach ($docsetFolder in $rootFolder.SubFolders)
{
#check document sets/folders of content type = "TestDocSet"
if($docsetFolder.Item.ContentType.Name -eq "TestDocSet")
{
write-host -f Yellow `t $docsetFolder.Name

#Iterating through the files within the document sets
foreach ($document in $docsetFolder.Files)
{
if(!$document.HasUniqueRoleAssignments)
{
write-host -f Cyan `t "  " $document.Name
write-host -f Red `t "     ..permissions inheritance detected. Process  
skipped"
}

}
}
}

$web.Dispose()
$siteURL.Dispose()

In my document set I have two documents 1 which has unique permissions set and the other inherits permissions.

I am expecting for the script to only show me documents/files which do not have unique permissions set, however I get all files instead. Is there something that I have missed on the check for unique permissinons above?

Thanks in advance for any suggestions.

The problem is where you are doing the check. The broken inheritance or in the case unique role assignments option is actually on the ListItem object. If you modify your code as follows it should work:

if(!$document.Item.HasUniqueRoleAssignments)
{
   write-host -f Cyan `t "  " $document.Name
   write-host -f Red `t "     ..permissions inheritance detected. Process skipped"
}

Let me know if you have any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM