当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用PowerShell从SharePoint的用户信息列表中获取用户部门、职位

作者:精品下载站 日期:2024-12-14 14:20:10 浏览:13 分类:玩电脑

使用PowerShell从SharePoint的用户信息列表中获取用户部门、职位


要求:根据业务需求,我们需要为 Intranet 门户网站的部门用户生成一份报告。比如说,“销售”部门有多少用户可以访问 SharePoint Intranet 门户?

解决方案:查询用户配置文件存储或用户信息列表以获取用户配置文件属性,例如部门、职位等。

PowerShell查询SharePoint中的用户信息列表

以下是如何使用 PowerShell 从 SharePoint 中的用户信息列表获取数据:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters  
$WebURL="https://portal.crescent.com"
$ReportLocation = "C:\UserAnalysisRpt.csv"

#Get the Web
$Web = Get-SPWeb $WebURL

#Get User information list
$UserInfoList = $Web.SiteUserInfoList

 #Get all Groups of the web and Iterate through    
 Foreach ($Group in $Web.Groups) 
 {
    #Get Permission Levels Applied to the Group   
    $RoleAssignment = $Web.RoleAssignments.GetAssignmentByPrincipal($Group)
 
    $RoleDefinitionNames=[string]::Empty
    foreach ($RoleDefinition in $RoleAssignment.RoleDefinitionBindings)
    {  
        $RoleDefinitionNames+=$RoleDefinition.Name+";"
    }
    #Array to Hold Result - PSObjects
    $ResultCollection = @()

    "Group Name: $($Group.name) : Permissions: $($RoleDefinitionNames)" >> $ReportLocation
    #Iterate through Each User in the group
        foreach ($User in $Group.users) 
        {
            #Get the User details from UIL
            $UserInfo = $UserInfoList.GetItemById($User.ID)            
            $Department = $UserInfo['Department']
            $JobTitle = $UserInfo["JobTitle"] 
            
            #Send the output the report file
            $User.name + "`t" + $user.Email + "`t" + $Department + "`t" + $JobTitle >> $ReportLocation
        }    
 } 
 Write-host "User analysis data has been Exported to $ReportLocation"

如果您想从配置文件存储中查询用户配置文件属性,请使用我的另一篇文章:在 SharePoint 2013 中使用 PowerShell 查询用户配置文件属性

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯