List all users and Group names in SharePoint 2013 and SharePoint 2016 using PowerShell

User group name in SharePoint 2013

User want to remediate the user permissions in SharePoint by deleting all the users added individually / directly by replacing them with AD user groups in SharePoint site collection and sub sites iteratively.
In general owners add users directly in SharePoint with their account name but this will be a major issue when we plan for migration from one version to another. This also causes problem of hanging resigned or old users in SharePoint.
I have implemented the below PowerShell script to list all the users across the site collections to list all the users with their group names iteratively.

#List all the Users with their Group name, Site name iteratively
$objSiteColl = Get-SPSite “http://sharepoint13:12345/” #Provide Site Collection URL
“Site Name`tGroup Name`tUser Name”
foreach ($objWeb in $objSiteColl.AllWebs)
    write-host -foregroundcolor yellow “`nWorking on web:” $objWeb.Title
    foreach ($objGrp in $objWeb.groups)
        #”Group: ” + $;
        $grpName = $
        write-host “`nGroup Name: ” $grpName  -foregroundcolor green
        foreach ($objUser in $objGrp.users)
            $objWeb.Title + “`t” + $ +”`t”+ $
            write-host “Login-ID:: ” $objUser.UserLogin  -foregroundcolor red


Write-Host “`nError:: $($_.Exception.Message)” -foregroundcolor red -BackgroundColor Yellow


How do we execute this script?
You can execute this script by following the below steps:
-> Log on to SharePoint WFE
-> Run SharePoint PowerShell IDE as administrator [Read a PowerShell tutorial on Windows PowerShell ISE]
-> Run the script with one of the 2 ways:
.\listAllUsers.ps1 | Out-File output.txt  -> this will generate an output file with tab delimiter
User group name in SharePoint 2013
User group name in SharePoint 2013
User group name in SharePoint 2016
User group name in SharePoint 2016

Hope this helps, Happy development in SharePoint PowerShell !!!

Check out Best Alternative to InfoPath -> Try Now

EnjoySharePoint YouTube Channel

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019

View all posts by Krishna Vandanapu →