获取在SharePoint中访问文档库的组的详细信息

时间:2015-05-06 14:15:33

标签: powershell sharepoint sharepoint-2013

我正在尝试访问可以访问SharePoint网站中的文档库的组信息(组名及其成员)。

请允许我用一个例子来解释:

对于名为" MyCompany"有财务,人力资源等子网站。每个子站点都有一个名为"共享文档"的文档库,并且在每个共享文档中都有文件夹和子文件夹。 对这些共享文档的访问权限被提供给不同的组,例如HR管理员可以访问HR子站点中的共享文档。 我想获取可以访问这些共享文档的组的数据,如下所示:

Site     : MyCompany (URL/Title)
Sub-site : HR (URL/Title)
Folder   : Shared Document  (Name/URL)
Group    : HR Managers
Member   : John 

我能够将组信息提取到子站点级别。但是可以在文档库和子文件夹级别执行此操作。

到目前为止我的脚本:

Add-PSSnapin Microsoft.Sharepoint.Powershell   
Start-SPAssignment -Global

$sysdate = Get-Date -UFormat "%m_%d_%y" 
$sites = get-spsite http://MyCompany_Url

$sites
foreach($site in $sites)
{
    [array]$users = $null
    #$name = $site.RootWeb.Title
    write-host -foregroundcolor green "Working on Site Collection: "$site.RootWeb.Title "..."
    foreach ($web in $site.AllWebs) 
    {
        write-host  "--Working on web:" $web.Title "..." -foregroundcolor yellow
        $webTitle = $web.Title
        foreach($l in $web.Lists)
        {
            #Check for only document libraries
            if($l.BaseType  -eq "DocumentLibrary")
            {
                if($l.Title -eq "Shared Documents")
                {
                    Write-Host $l.Title"(Web: "$web.Title")" -ForegroundColor DarkRed -BackgroundColor White
                    $grpinfo = $l.RoleAssignments
                    $groupinfo

                    <#foreach($item in $l.Items)
                    {
                        $ItemUrl   = $item.Url
                        $ItemTitle = $item.Title

                        Write-Host $item.Url" : "$item.Title -ForegroundColor green 
                    }#>

                }
            }
        }
        # # Getting group ifo at sub-site level
        foreach ($group in $web.groups)
        {
            write-host  "----Collecting users from group:"$group.Name "..." -ForegroundColor Magenta

            #$GrpPermission = $roles.Type + ":"+ $roles.Name
            foreach($user in $group.users)
            {
                $usrname   = $user.DisplayName
                $UserPerm  = $user.Roles
                $GroupPerm = $group.Roles

                [string]$UPerm = @($UserPerm.Name) -join ","
                [string]$GPerm = @($GroupPerm.Name) -join "," #-replace (" ", ",")
                Write-Host "################"
                $GPerm
                Write-Host "----------------"
                $UPerm
                Write-Host "################"

                write-host "-----"$user.DisplayName" : "$group.name" : "$web.Title" : "$site.RootWeb.Title " Group Permission : "$group.Roles  " Member Permission : "$user.Roles -ForegroundColor Blue -BackgroundColor White
                $users = new-object psobject
                $users | Add-Member NoteProperty -name "Webpart Name"          -value $web.Title
                $users | add-member noteproperty -name "Groups"                -value $group.name
                $users | add-member noteproperty -name "Display Name"          -value $user.DisplayName
                $users | add-member noteproperty -name "Group Permission(s)"   -value $GPerm
                $users | add-member noteproperty -name "Webpart URL"           -value $web.Url
                #$users
                $users  | export-csv -path "E:\MyCompany_Groups_report_$sysdate.xls" -Append -NoTypeInformation             
            }
        } 
        $web.Dispose()
    }
    $site.Dispose()
}
Stop-SPAssignment -Global

0 个答案:

没有答案