Introduction
This article explains how to export the SP2013 group names in Excel using a Powershell script.
Prerequisites
- Ensure you have created a site collection and groups in a site collection.
- Ensure you have a Powershell window to execute the script.
Use the following procedure
- Add the following lines of code in a a text editor such as Notepad.
- Save the file as "GetAllGroups.ps1".
#get the site object
$site = Get-SPSite “ http:// yoursitecollection”
#get the group collection details
$groups = $site.RootWeb.sitegroups
#output variable is been used for storing the group details.
$Output = @("GroupName")
#loop thru the groups object and get the individual group details.
foreach ($grp in $groups)
{
Write-Host "Group: " $grp.name;
$Output += ($grp.name)
}
$site.Dispose()
#finally export the group names to the .csv file
$Output > "C:\ ExportGroups.csv"
- In the code above snippet you are initialising a site object.
- Then in line 2, get the group collection details using the sitegroups property.
- Loop in the groups object to get the group name details in the site collection.
- Then finally dipose the site object and export the group names to the .csv file.
- Output variable has been used to store the group names.
- That's it!!Now let's start testing.
Testing
- Now to run the script, open the Powershell window by clicking on Run as administrator.
- Now navigate to the location where you have placed your Powershell script; in our case it's “GetAllGroups.ps1” at the location (cd “C:\GetAllGroups.ps1”).
- Click on the Enter button. Thats it.
- Now navigate to the “C:\” drive and you will be able to see the ExportGroups.csv file placed in ur “C:\” drive.
- If you open the document then you will be able to see the groups name in the CSV file.
Summary
Thus in this article you saw how to export the SP2013 group names in Excel/CSV using Powershell script.