Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: Get All Users In A SharePoint 2010/13/16 Farm Using PowerShell Script
Welcome to an article on how to get all users in a SharePoint 2010/13/16 farm using PowerShell Script. This script is going to run and loop in all the web applications and site collections within them and get individual and group users.
This script will help save us developers a lot of time in getting all the users from an individual or group. So, here is the script.
- Copy the code below to a .ps1 file.
- Run the .ps1 file on the SharePoint PowerShell modules.
- You don’t need to do any update on the script.
Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#getalluserinthefarm Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue $Currentime = get-date -format "yyyyMMdd_hhmmtt" $filename = "FarmUsers" $datafile = ("{0}{1}.csv" -f $filename, $Currentime) $headerfile = "type,user,group,weburl,webtitle" $headerfile | out-file -FilePath $datafile $iissitedata = get-spwebapplication foreach($farmsite in $iissitedata) { foreach ($SiteCollection in $farmsite.sites) { write-host $SiteCollection -foregroundcolor Blue foreach ($web in $SiteCollection.Allwebs) { write-host " " $web.url $web.name "users:" -foregroundcolor yellow foreach ($usersite in $web.users) { write-host " " $usersite -foregroundcolor white $data = ("RootUser,{0},-,{1},{2}" -f $usersite, $web.url,$web.name) $data | out-file -FilePath $datafile -append } foreach ($group in $web.Groups) { Write-host " " $web.url $group.name: -foregroundcolor green foreach ($user in $group.users) { Write-host " " $user -foregroundcolor white $data = ("GroupUser,{0},{1},{2},{3}" -f $user, $group, $web.url, $web.name) $data | out-file -FilePath $datafile -append } } $web.Dispose() } } } |
Once you initiate the script, it will run through all site collections in all the webs and populate the date and save it in on the same location you are running it from, in a .csv or .txt format.
Just run this script and you will get all the users on the farm.
Print article | This entry was posted by Peter on January 11, 2018 at 7:24 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |