Create SharePoint 2013 site collection group using PowerShell

InfoPath alternatives for form designing SharePoint

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.

Before that you can check few posts on:
– Create SharePoint List using out of box or custom template using PowerShell

– Create Site Collection PowerShell Script SharePoint 2013 or 2010

– Create Folders CSOM PowerShell Script Office 365 SharePoint Online

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.

Thanks,
Sambita

Similar SharePoint 2013 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 →

Leave a Reply