How to create custom sharepoint group and add permission level using powershell

 

 

$siteURL="http://servername:10/"

$groupName="Custom Group"

$permissionLevel="Contribute"

$description="My custom Group using powershell"

 

 

$site=Get-SPSite $siteURL

$web=$site.RootWeb

$newGroup=$web.SiteGroups.Add($groupName,$web.CurrentUser,$null,)

$group=$web.SiteGroups[$groupName]

$roleAssignment=New-Object Microsoft.SharePoint.SPRoleAssignment($group)

$roleDefinition=$web.RoleDefinitions[$permissionLevel]

$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)

$web.RoleAssignments.Add($roleAssignment);

$web.Update()

$web.Dispose()

$site.Dispose()