简体   繁体   English

检查文档集中文件/文档的权限

[英]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: 到目前为止,我已经拥有followin脚本,但是由于某种原因,检查无法正常进行/恢复预期的结果:

$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. 在我的文档集中,有两个文档1具有唯一的权限集,另一个文档继承了权限。

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. 断开的继承或唯一的角色分配选项实际上在ListItem对象上。 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. 如果您有任何疑问,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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