Friday, January 30, 2015

Create a SharePoint Group using PowerShell

Here is my script to create new SharePoint group using PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue

#Custom Function to Create new SharePoint Group
function Create-SPGroup
    param ($SiteURL, $GroupName, $PermissionLevel, $GroupDescription)  

        #Get the Web
        $web = Get-SPWeb -Identity $SiteURL
        if($web -ne $null)
            #Check if Group Exists already
            if ($web.SiteGroups[$GroupName] -ne $null)  
                write-Host "Group $GroupName exists Already!" -ForegroundColor Red 
                #Create SharePoint Group
                $Web.SiteGroups.Add($GroupName, $web.Site.Owner, $web.Site.Owner, $GroupDescription)  
                #Get the newly created group and assign permission to it
                $Group = $web.SiteGroups[$groupName]  
                $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)  
                $roleDefinition = $web.Site.RootWeb.RoleDefinitions[$permissionLevel]  

                write-Host "Group: $GroupName created successfully!" -ForegroundColor Green
    catch [System.Exception]
        write-host $_.Exception.ToString() -ForegroundColor Red 

#Call the function to create Sharepoint group
Create-SPGroup "" "Sales Managers" "Edit" "Group for Sales Managers" 

Tags: create a SharePoint group powershell, create new SharePoint group powershell, create permission group SharePoint 2013 powershell, create SharePoint security group powershell, create SharePoint user group using powershell, powershell to create SharePoint group

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

1 comment :

  1. How can we add custom webpart to NewForm.aspx page (default) using "power shell script in sharepoint 2013".

    Ex: I have MyCustomList and add new item,i will get NewForm.aspx in that i need to add my custom(visual webpart)to the page using powershell script.

    Kindly let us know any one developed or any suggestions




Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...