Get all SharePoint Users in CSV File from Farm using PowerShell in SharePoint


In this post we will discuss how we can get all the SharePoint users in CSV file presented in farm using PowerShell in SharePoint 2013. This is a script that gets each SharePoint site on the farm, enumerates all the site collections and webs and dumps them to the screen as well as a CSV file.

The Current date and time is always appended to the file name so you don’t have to worry about wiping out previous results.

Read some SharePoint tutorials

Hub Sites SharePoint Online Office 365 Tutorial Download PDF Free

SharePoint Server 2016 Installation step by step

How to do an IISReset in all the servers in a SharePoint Farm?


Below is the PowerShell Script to Get All the Users:

#getalluserseverywhere

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$timestamp = get-date -format “yyyyMMdd_hhmmtt”

$filenameStart = “AllFARMUsers”

$logfile = (“{0}{1}.csv” -f $filenamestart, $timestamp)

$header = “type,user,group,weburl,webname”

$header | out-file -FilePath $logfile

$iissitelist = get-spwebapplication

foreach($onesite in $iissitelist)

{

foreach ($SiteCollection in $onesite.sites)

{

write-host $SiteCollection -foregroundcolor Blue

foreach ($web in $SiteCollection.Allwebs)

{

write-host ” ” $web.url $web.name “users:” -foregroundcolor yellow

# Write-host ” ” $web.users | select name

foreach ($userw in $web.users)

{

#if ($userw -like “domain\*”)

#{

write-host ” ” $userw -foregroundcolor white

#$msg = (“{0},{1} user:{2}” -f $web.url,$web.name, $userw)

$msg = (“RootUser,{0},-,{1},{2}” -f $userw, $web.url,$web.name)

$msg | out-file -FilePath $logfile -append

# }

}

foreach ($group in $web.Groups)

{

Write-host ” ” $web.url $group.name: -foregroundcolor green

foreach ($user in $group.users)

{

# if ($user -like “Domain\*”)

#{

Write-host ” ” $user -foregroundcolor white

#$msg = (“{0},{1},group:{2}, user:{3}” -f $web.url, $web.name, $group, $user)

$msg = (“GroupUser,{0},{1},{2},{3}” -f $user, $group, $web.url, $web.name)

$msg | out-file -FilePath $logfile -append

#}

}

}

$web.Dispose()

}

}

}

Hope this will be helpful.


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply