Export user list from SharePoint groups using PowerShell script

Advertisement
 We can get all users from all groups in SharePoint using below script. Using the below script we can get sub rooms users also.
  
Add-PsSnapin Microsoft.SharePoint.PowerShell


$URL= "https://Dotnetsharepoint.com"

     $site = Get-SPSite $URL
   
     #Write the Header to "Tab Separated Text File"
        "Site Name `t Group Name `t User Name “| out-file "D:\SPUsersList.xslx"
       
     #Iterate through all Webs (All Sub rooms)
      foreach ($web in $site.AllWebs)
      {
        #Write the Header to "Tab Separated Text File"
        "$($web.title) `t" | out-file "D:\SPUsersList.xslx" -append

         #Get all Groups  
         foreach ($group in $Web.groups)
         {
                "`t `t $($Group.Name)" | out-file "D:\SPUsersList.xslx" -append
             
                        foreach ($user in $group.users)
                        {
                           #Exclude Built-in User Accounts                            

                                "`t `t `t $($user.name)" | out-file "D:\SPUsersList.xslx" -append
                        }
         }
     }

    write-host "Report Generated at D:\SPUsersList.xlsx"
Advertisements
SHARE

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a comment