Create SharePoint 2013 site collection group using PowerShell


In this post I will be sharing PowerShell script to create groups in SharePoint Site collection. The PowerShell script is applicable to both SharePoint 2013 and SharePoint 2010.

Kindly create SiteCollectionGroups.CSV file and add below columns to keep input values.

SiteCollectionURL
GroupName

The file will look like below image.

Create SharePoint 2013 site collection group using PowerShell
Create SharePoint 2013 site collection group using PowerShell


PowerShell Script Code:

$0 = $MyInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
$path = $(“$dp0\SiteCollectionGroups.csv”)
$csv = Import-csv -path $path

foreach($line in $csv)

{

$siteCollURL = $line.SiteCollectionURL
$groupName = $line.GroupName

write-host $siteCollURL “….” $groupName

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) | Out-null

$site = New-Object Microsoft.SharePoint.SPSite($siteCollURL)
$web = $site.RootWeb;

$exists = $web.SiteGroups | where { $_.Name -eq $groupName }

if ($exists -eq $null)
{
$web.SiteGroups.Add($groupName,$web.CurrentUser,$web.CurrentUser,$groupName)
Write-Host $groupName ” is created in ” $siteCollURL “….”
}

$web.Close
$site.Close

}

Now Groups are created. I will be sharing code to map permission with respective group in my next post.

Read some SharePoint csom articles:


Thanks,
Sambita

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →