Sunday, 9 April 2017

Export SharePoint Group members to .csv

Export SP Group members to .csv 

# Script for extracting members of SP groups in a site to a .csv file

This is how it looks in ISE:



Here is the Powershell:


Add-PSSnapin "Microsoft.SharePoint.PowerShell"

function global:Get-SPSite($url)
 {
    return new-Object Microsoft.SharePoint.SPSite($url)
 }

function global:Get-SPWeb($url)
{
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
            {
               $web=$site.OpenWeb();     
            }
    return $web
}

$URL="https://extranet.domain/sites/Meetings"
     $site = Get-SPSite $URL
    
     #Write the Header to "Tab Separated Text File"
        "Site Name`t  URL `t Group Name `t User Account `t User Name `t E-Mail" | out-file "c:\Scripts\UsersandGroupsRpt.txt"
        
     #Iterate through all Webs
      foreach ($web in $site.AllWebs)
      {
        #Write the Header to "Tab Separated Text File"
        "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "c:\Scripts\UsersandGroupsRpt.txt" -append
         #Get all Groups and Iterate through  
         foreach ($group in $Web.groups)
         {
                "`t  `t $($Group.Name) `t   `t `t " | out-file "c:\Scripts\UsersandGroupsRpt.txt" -append
                #Iterate through Each User in the group
                       foreach ($user in $group.users)
                        {
                           #Exclude Built-in User Accounts
                    if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
                    {
                                "`t  `t  `t  $($user.LoginName)  `t  $($user.name) `t  $($user.Email)" | out-file "c:\Scripts\UsersandGroupsRpt.txt" -append
                             }
                        }
         }
       }

    write-host "Report Generated at c:\Scripts\UsersandGroupsRpt.txt"






No comments:

Post a Comment

SharePoint Information Architecture Diagram

Here is the template I use for Information Architecture designs. It's built using Mindjet and I flesh the nodes out with the low level d...