How to find Number of users in sharepoint 2013 farm? How to find number of site collections and web applications on the farm?

Using a script in Powershell

1 Answer 1


I think it is better to slpit your question into two...

Here is script to get all users in the farm.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Output Report File
$currentLocation = (Get-Location).Path
$outputReport = $currentLocation + "\" + "SharePointUsers.csv"
#Write CSV File Header

#Array to hold user data
$UserDataCollection = @()

#Get All Web Applications and iterate through
$WebAppsColl = Get-SPWebApplication
#To Get all Users from specific web application, Use: $WeAppsColl = Get-SPWebApplication "web-app-url"
#and remove line #12

foreach($WebApp in $WebAppsColl)
    Write-host "Scanning Web Application:"$WebApp.Name
    #Get All site collections and iterate through
    $SitesColl = $WebApp.Sites
    #To Get all Users from site collection, Use: $SitesColl = Get-SPSite "site-collection-url"
    #and remove lines between #11 to #20 and Line #55 "}"
    #get all users from site collection PowerShell
    foreach ($Site in $SitesColl)
        Write-host "Scanning Site Collection:"$Site.URL
        #Get All Webs and iterate through
        $WebsColl = $Site.AllWebs
        #To Get all Users from aq site, Use: $WebsColl = Get-SPWeb "web-url"
         #and remove lines between #11 to #28 and Lines #53, #54, #55 "}"

            foreach ($web in $WebsColl)
                Write-host "Scanning Web:"$Web.URL
                #Get All Users of the Web
                $UsersColl = $web.AllUsers  #get all users programmatically
                    #list all users
                    foreach ($user in $UsersColl)
                           if($User.IsDomainGroup -eq $false)
                                $UserData = New-Object PSObject

                                $UserData | Add-Member -type NoteProperty -name "UserLogin" -value $user.UserLogin.ToString()
                                $UserData | Add-Member -type NoteProperty -name "DisplayName" -value $user.displayName.ToString()
                                $UserData | Add-Member -type NoteProperty -name "E-mailID" -value $user.Email.ToString()

                                $UserDataCollection += $UserData
    #Remove duplicates
    $UserDataCollection = $UserDataCollection | sort-object -Property  {$_.UserLogin } -Unique

    #Remove duplicates and export all users to excel
    $UserDataCollection | Export-Csv -LiteralPath $OutputReport -NoTypeInformation

    Write-host "Total Number of Unique Users found:"$UserDataCollection.Length

Read more: http://www.sharepointdiary.com/2014/12/get-all-users-of-sharepoint-site-collection-web-app-farm.html#ixzz4DdqPtCWb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.