• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • Forums
  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings
Home » Backend (Server-Side) » Get List Of SharePoint Users With PowerShell

Get List Of SharePoint Users With PowerShell

October 22, 2019 by Ehi Kioya Leave a Comment

Two PowerShell code snippets for getting a list of SharePoint users.

This first script takes your absolute site collection URL as input and prints out the login names of all the users within the SiteUsers property.

$siteColURL = "Your absolute site collection URL"
$siteCollection = new-object Microsoft.SharePoint.SPSite($siteColURL)
$spWeb = $siteCollection.openweb()
$users = $spWeb.SiteUsers
foreach($user in $users) {
	Write-Host " ------------------------------ "
	Write-Host "Site collection URL:", $siteColURL
	if($user.IsSiteAdmin -eq $true) {
		Write-Host "Site Admin: ", $user.LoginName
	}
	else { 
		Write-Host "Site User: ", $user.LoginName
	}
	Write-Host " ------------------------------ "
}
$spWeb.Dispose()
$siteCollection.Dispose()

The second script below builds on the first. It also takes the absolute URL of your site collection as input. In addition, it takes the name of a specific SharePoint list as an extra input.

$siteColURL = "Your absolute site collection URL"
$listName = "Your SPList name"
$siteCollection = new-object Microsoft.SharePoint.SPSite($siteColURL)
$spWeb = $siteCollection.openweb()
$spList = $spWeb.Lists[$listName]
$users = $spWeb.SiteUsers
foreach($user in $users) {
	Write-Host " ------------------------------ "
	Write-Host "Site collection URL:", $siteColURL
	if($spList.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$user) -eq $true) {
		Write-Host "Site User: ", $user.LoginName
		Write-Host "User Permissions: ", $spList.GetUserEffectivePermissions($user.LoginName)
	}
	Write-Host " ------------------------------ "
}
$spWeb.Dispose()
$siteCollection.Dispose()

When you execute the code snippet above, it loops through all the SharePoint users in the SiteUsers property of the “openweb()”. Then it checks if each user has any permissions on the specified list.

If a user has any permissions on the list, the user’s login name is printed to screen along with the permissions they have.

Found this article valuable? Want to show your appreciation? Here are some options:

  1. Spread the word! Use these buttons to share this link on your favorite social media sites.
  2. Help me share this on . . .

    • Facebook
    • Twitter
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Skype
  3. Sign up to join my audience and receive email notifications when I publish new content.
  4. Contribute by adding a comment using the comments section below.
  5. Follow me on Twitter, LinkedIn, and Facebook.

Related

Filed Under: Backend (Server-Side), PowerShell, SharePoint, Snippets Tagged With: Permissions, PowerShell, SharePoint, Users

About Ehi Kioya

I am a Toronto-based Software Engineer. I run this website as part hobby and part business.

To share your thoughts or get help with any of my posts, please drop a comment at the appropriate link.

You can contact me using the form on this page. I'm also on Twitter, LinkedIn, and Facebook.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

26,136
Followers
Follow
30,000
Connections
Connect
14,643
Page Fans
Like
  • Recently   Popular   Posts   &   Pages
  • Actual Size Online Ruler Actual Size Online Ruler
    I created this page to measure your screen resolution and produce an online ruler of actual size. It's powered with JavaScript and HTML5.
  • Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library
    This article explains how to bypass the single user remote desktop connection restriction on Windows 10 by using the RDP wrapper library.
  • WordPress Password Hash Generator WordPress Password Hash Generator
    With this WordPress Password Hash Generator, you can convert a password to its hash, and then set a new password directly in the database.
  • Forums
  • About
  • Contact

© 2021   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy