简体   繁体   English

从SharePoint中删除不需要的用户权限

[英]Remove unwanted user permissions from SharePoint

I have a POSH script that sets a user's access to a specific folder for some files to read. 我有一个POSH脚本,用于设置用户对特定文件夹的访问权限,以读取某些文件。

The user's group gets assigned to the folder (which happens to be the same name). 用户的组将分配给该文件夹(碰巧是相同的名称)。

I then created a new view, set it to default, and told it to display all files without folders. 然后,我创建了一个新视图,将其设置为默认视图,并告诉它显示所有没有文件夹的文件。

This script has been working perfectly for 4 months but now some people want to use the mobile view and I am running into an issue. 该脚本已经完美运行了4个月,但是现在有些人想要使用移动视图,而我遇到了一个问题。 If a user does not have read access from the root directory to the folder in question, SharePoints mobile view will not show the folder. 如果用户没有从根目录到相关文件夹的读取访问权限,则SharePoints移动视图将不会显示该文件夹。

For example the user has the following permissions set: Limited Access on the root Limited Access on the Alpha folder Read access to the folder under Alpha 例如,用户设置了以下权限:根目录上的“受限访问” Alpha文件夹上的“受限访问”读取对Alpha下的文件夹的访问

I need to make it so a user can view this in the mobile view. 我需要这样做,以便用户可以在移动视图中查看它。

Here is my code: 这是我的代码:

#region Start
# Create Connection to stopwatch diagnostics
[Void][System.Diagnostics.Stopwatch] $sw;
# New Stopwatch object
$sw = New-Object System.Diagnostics.StopWatch;
# Stop any watches that might be running
$sw.Stop();                                         
$sw.Start();
clear
[int]$a = 0;
# Which folders to assign
[array]$sections = "Alpha","Bravo","Charlie","Delta";
[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
#endregion

#region The meat and potatoes
foreach ($section in $sections) {
    #region get the Directories
    $pathtowd = "\\path\to\webdav\$section";                                    # UNC Path to the pivots
    $dirs = Get-ChildItem $pathtowd | Where-Object { $_.Attributes -band [System.IO.FileAttributes]::Directory }
    #endregion

    #region Connect to SharePoint
    $SPSite = New-Object Microsoft.SharePoint.SPSite("http://sharepoint");                  # Connect to SharePoint
    $OpenWeb = $SpSite.OpenWeb("/Downloads");                                               # Subsite of downloads
    #endregion
    [int]$i = 0;                                                                            # Integer to increment
    foreach ($dir in $dirs) {
        $verify_groups = $OpenWeb.groups | ? {$_.Name -eq "$dir"; }                         # Verify the groups
        if ($verify_groups -ne $null) {
            if ($dir.ToString() -eq $verify_groups.ToString()) {
                $i++;                                                                       # Increment the groups
                Write-Host "[", $sw.Elapsed.ToString(), "] -",$dir -F Green;                # Output status
                $path = "http://sharepoint/Downloads/Pivots/$section/" + $dir;              # Set the Path
                $spc = $OpenWeb.SiteGroups;                                                 # SharePoint connection
                $group = $spc[$dir];                                                        # Directory
                $roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($group); # Role Assignment connection
                $OpenWeb.GetFolder($path).Item.BreakRoleInheritance("true");                # Break inheritance
                $roleAssignment.RoleDefinitionBindings.Add($OpenWeb.RoleDefinitions["Read"]);# Set permissions
                $OpenWeb.GetFolder($path).Item.RoleAssignments.Add($roleAssignment);        # Add the role
                $OpenWeb.GetFolder($path).Item.Update();
            }
            else { Write-Host "[", $sw.Elapsed.ToString(), "] -", $verify_groups " is empty"; }
        }
    }
    Write-Host '[' $sw.Elapsed.ToString() '] - found '$i' Folders' -f Red;                  # Output Status
    $SPSite.Dispose();                                                                      # Dispose the connection
    $OpenWeb.Dispose();
    $a = $a+$i;                                                                             # Total Folders
}
#endregion

$sw.Stop();                                                                             # Stop the timer
[string]$howlong = $sw.Elapsed.ToString();                                              # How long
write-host "Updated in Time: " $howlong -F Green;                                       # Last message

Found it. 找到了。 Took 4 hours straight of trial and error but it works. 连续进行了4个小时的反复试验,但仍然有效。 Hope this helps someone else out as well. 希望这也能帮助其他人。 Place before $OpenWeb.GetFolder($path).Item.Update(); 放在$ OpenWeb.GetFolder($ path).Item.Update();之前;

$returnGroups = $OpenWeb.GetFolder($path).Item.RoleAssignments | `
        where {`
         ($_.RoleDefinitionBindings -eq $OpenWeb.RoleDefinitions["Limited Access"]) -and `
         ($_.RoleDefinitionBindings -notcontains $OpenWeb.RoleDefinitions["Read"])`
        };
        if ($returnGroups -not $null)
        {
         foreach ($item in $returnGroups)
         {
          Write-Host "Removing: " $item.Member;
          $OpenWeb.GetFolder($path).Item.RoleAssignments.Remove($spc[$item.Member]);
         }
        }

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

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