1

Some of my groups were deleted due to some mistake, wanna create a new group and apply permission level on these groups. is there any way I can do these using PowerShell by reading a CSV file like

   groupName      permissions level  

   grp1           read 
   grp2           contribute 
   grp3           contributenodelete 

      $groups = $site.RootWeb.sitegroups

      $COUNGRP= $groups.COUNT

      Write-Host $COUNGRP

      $mdate=  get-date -f yyyy/MM/dd-HHmm

      $csvfilename= "E:\PoCSolutions\spgroupsforcreation.csv"; 
      cls

1 Answer 1

1

I am using PnPPowerShell to create groups and permissions.

Here is my CSV

GroupName,PermissionLevel
Test1,Read
Test2,Contribute

Here is snippet to create groups from the CSV

cls

$cred = Get-Credential -UserName "<<username>>" -Message "Enter password"

Connect-PnPOnline -Url "<<site collection url>>" -Credentials $cred
$csvGroups = Import-Csv "C:\Temp\Groups.csv"

foreach($grp in $csvGroups) {
    Write-Host $grp.GroupName
    $newGroup = New-PnPGroup -Title $grp.GroupName
    $role = $grp.PermissionLevel

    Set-PnPGroup -AddRole -Title $newGroup.Title -Identity $newGroup.Id

}

Disconnect-PnPOnline

Here are the reference articles for additional information

How to create a SharePoint group

How to update a group with permissions

2
  • I think this is meant for SPO, I am on on-prem. So whether MS has released the PnPPowerShell for on-prem? anyway, thanks for the sample code , i will try to build from your code. Commented Jun 16, 2017 at 15:49
  • 1
    Yes. There is a different version for On-premises which you can download from here. msdn.microsoft.com/en-us/pnp_powershell/pnp-powershell-overview Commented Jun 16, 2017 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.