kwizcom banner advertisement

Get User Department, Job Title from User Information List of SharePoint using PowerShell

Requirement: From a business requirement, need to generate a report for department wise users of a Intranet portal site. Say, How many users from "Sales" department have access to SharePoint Intranet portal?

Solution: Either query user profiles store or user information list to get the user profile properties such as Department, Job title, etc.

PowerShell to query User Information List in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters  
$WebURL="http://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=""
    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"

If you want to go for querying user profile properties from profile store, use my another post: Query User Profile Properties using PowerShell in SharePoint 2013
Get User Department, Job Title from User Information List of SharePoint using PowerShell Get User Department, Job Title from User Information List of SharePoint using PowerShell Reviewed by Salaudeen Rajack on 3:03 PM Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.