0

我試圖遍歷文檔集中的文檔集,並列出文件/文檔(如果它們具有「獨特權限」)。我有跟隨着腳本到目前爲止,但由於某些原因,檢查是不工作/帶回了預期的結果:檢查文檔集內文件/文檔的權限

$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() 

在我的文檔集,我有兩個文件1,它具有一組唯一的權限和其他繼承權限。

我期待腳本只顯示我沒有設置唯一權限的文檔/文件,但是我得到所有文件。有沒有我在上面檢查獨特的許可證時錯過了什麼?

在此先感謝您的任何建議。

回答

1

問題是你在做檢查的地方。斷開的繼承或案例中的唯一角色分配選項實際上是ListItem對象。如果你修改你的代碼如下它應該工作:

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

讓我知道如果您有任何問題。

+0

非常感謝您的回覆David,現在工作正常。 –