Sunday, September 25, 2016

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  
$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)
    foreach ($RoleDefinition in $RoleAssignment.RoleDefinitionBindings)
    #Array to Hold Result - PSObjects
    $ResultCollection = @()

    "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
            $ + "`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

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...