Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从SharePoint中删除不需要的用户权限_Sharepoint_Powershell - Fatal编程技术网

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

从SharePoint中删除不需要的用户权限,sharepoint,powershell,Sharepoint,Powershell,我有一个高级脚本,它设置用户对特定文件夹的访问权限,以便读取某些文件 用户的组被分配到恰好同名的文件夹 然后我创建了一个新视图,将其设置为默认值,并告诉它显示所有不带文件夹的文件 这个脚本已经完美运行了4个月,但是现在有些人想要使用移动视图,我遇到了一个问题。如果用户没有从根目录读取相关文件夹的权限,SharePoints mobile view将不会显示该文件夹 例如,用户设置了以下权限: 根目录上的有限访问权限 对Alpha文件夹的访问受限 对Alpha下文件夹的读取访问权限 我需要这样做,

我有一个高级脚本,它设置用户对特定文件夹的访问权限,以便读取某些文件

用户的组被分配到恰好同名的文件夹

然后我创建了一个新视图,将其设置为默认值,并告诉它显示所有不带文件夹的文件

这个脚本已经完美运行了4个月,但是现在有些人想要使用移动视图,我遇到了一个问题。如果用户没有从根目录读取相关文件夹的权限,SharePoints mobile view将不会显示该文件夹

例如,用户设置了以下权限: 根目录上的有限访问权限 对Alpha文件夹的访问受限 对Alpha下文件夹的读取访问权限

我需要这样做,以便用户可以在移动视图中查看

这是我的密码:

#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

找到了。连续4个小时的尝试和错误,但它的工作。希望这对其他人也有帮助。放置在$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]);
         }
        }

我知道有一个Item.roleasignments.Remove命令,但我还没有找到一种方法来列出所有当前分配的组,以便循环并删除它们。希望这对你们有帮助!