【问题标题】:Removing per-item permissions by powershell?通过powershell删除每个项目的权限?
【发布时间】:2014-11-14 08:05:55
【问题描述】:

我有一个 SharePoint 列表。在此列表中,每个项目都有自己的用户权限。由于设计更改,我想删除项目权限并从列表中恢复标准继承权限。

因为该列表中有数百个项目:这可以通过 powershell 脚本完成吗?可以举个例子吗?

【问题讨论】:

    标签: powershell sharepoint


    【解决方案1】:

    在 technet 上找到了我的问题的解决方案:

    http://gallery.technet.microsoft.com/office/PowerShell-to-Reset-Unique-d885a93f

    ###############################################################################  
    ##  ADD IN SHAREPOINT SNAP IN IF NOT ALREADY LOADED ##  
    ###############################################################################  
    
    
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {  
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"  
    } 
    
    
    ###############################################################################  
    ##  SET VARIABLES FROM ARGUMENTS ##  
    ###############################################################################  
    
    $webUrl = $args[0] 
    $listName = $args[1] 
    $listInherits = $args[2] 
    
    # Varibale to hold document count 
    $count = 0 
    
    ###############################################################################  
    ##  OPEN OBJECTS & RESTORE INHERITANCE ##  
    ############################################################################### 
    
    try { 
        # Open the web and list objects 
        $web = Get-SPWeb $webUrl 
        $list = $web.Lists[$listName] 
    
        # If the list should inherit, reset the role inheritance 
        if ($listInherits -eq $true) { 
            $list.ResetRoleInheritance() 
            Write-Host "Updated permissions on list." -foregroundcolor Green 
        } 
    
        # Get all items with unique permissions 
        $itemsWithUniquePermissions = $list.GetItemsWithUniquePermissions() 
        Write-Host $itemsWithUniquePermissions.Count "number of items with unique permissions found." 
    
        # Only update items if some exist 
        if ($itemsWithUniquePermissions.Count -gt 0) { 
            foreach ($itemInfo in $itemsWithUniquePermissions) { 
                $item = $list.GetItemById($itemInfo.Id) 
                    $item.ResetRoleInheritance() 
                $count++ 
            } 
    
            # Display number of items updated 
            Write-Host "Updated permissions on $count items." -foregroundcolor Green 
        } 
        else { 
            Write-Host "No items with unique permissions exist, nothing to update." 
        } 
    
        # Dispose of web object 
        $web.Dispose() 
    } 
    catch [Exception] { 
        Write-Host "Exception encountered.  Please ensure all arguments are valid." -foregroundcolor Red 
        Write-Host $_.Exception.Message -foregroundcolor Red 
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 2012-08-30
      • 1970-01-01
      • 2015-06-12
      • 2019-04-23
      • 2013-05-23
      • 1970-01-01
      • 2016-06-02
      • 2013-02-07
      相关资源
      最近更新 更多