Provision / Security

Create SharePoint Groups in Bulk using CSV file

This script shows how to create multiple groups in SharePoint for different site collection providing input from CSV file.

Summary

This script shows how to create multiple groups in SharePoint for different site collection providing input from CSV file.

Implementation

  • Open Windows PowerShell ISE
  • Create a new file
  • Write a script as below,
  • Create a CSV using the provided sample. Two columns are required SharePointUrl and SharePointGroupName
  • Then we provide the path of the file as input to the PowerShell when prompted in the window when executed.

Download Sample CSV from this link

Execution Image and output Image

ExecutionImage

OutPutImage

powershell

#Uncomment below line if facing remote server 400 error
#Import-Module SharePointPnPPowerShellOnline -UseWindowsPowerShell

$filePath = Read-Host "Please provide CSV file path"

# Import CSV file from given path
$importedFile = Import-Csv -Path $filePath

for ($index = 0; $index -lt $importedFile.Count; $index++) {
    # Connect to SharePoint online site
    Connect-PnPOnline -Url $importedFile[$index].SharePointUrl -Interactive

    # Create a new group in SharePoint site
    New-PnPGroup -Title $importedFile[$index].SharePointGroupName
}

Contributors

Author(s)
Kunj Sangani
Ganesh Sanap

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Tool documentation & references

Keep exploring