Multipile site creation issue

sns 9,236 Reputation points
2022-11-30T16:47:26.197+00:00

I have list of site collection names in CSV with column name title, I want to create 100 site collections with title mentioned in the CSV and also URL also should be same as title, with managed path teams. is there any script for this, if yes please share, thank you in advance.

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,971 questions
0 comments No comments
{count} votes

Accepted answer
  1. AllenXu-MSFT 21,666 Reputation points Microsoft Vendor
    2022-12-01T02:53:34.02+00:00

    Hi @sns ,

    For SharePoint Server:

    • Step 1: Create a CSV file in the below format. Populate the column values according to your requirements.
      265956-image.png
    • Step 2: Use this PowerShell script to read from CSV and create site collections in bulk. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue # Function to Create new Site Collection Function Create-SPSite
      {
      param
      (
      [string]$Name = $(throw "Please Provide the Site Name!"),
      [string]$URL = $(throw "Please Provide the Site URL!"),
      [string]$Owner = $(throw "Please Provide the Site Owner!"),
      [string]$Template = $(throw "Please Provide the Site Template!")
      )
      Try {
      #Set the Error Action
      $ErrorActionPreference = "Stop"
      #Check if the site collection exists already  
      $SiteExists = Get-SPSite | where {$_.url -eq $URL}  
      #Check if site exists in the recycle bin  
      $SiteExistsInRecycleBin = Get-SPDeletedSite | where {$_.url -eq $URL}  
      
      If($SiteExists -ne $null)  
      {  
          write-host "Site $($url) exists already!" -foregroundcolor red  
      }  
      elseIf($SiteExistsInRecycleBin -ne $null)  
      {  
          write-host "Site $($url) exists in the recycle bin!" -foregroundcolor red  
      }  
      else  
      {  
          #create site collection  
          New-SPSite -Url $URL -Name $Name -OwnerAlias $Owner -Template $Template  
          write-host "Site Collection $($url) Created Successfully!" -foregroundcolor Green  
      }  
      
      }
      catch {
      write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
      }
      Finally {
      #Reset the Error Action to Default
      $ErrorActionPreference = "Continue"
      }
      } # Read from CSV and create site collection Import-Csv "C:\SitesToCreate.csv" | Foreach-Object {
      Create-SPSite -Name $.SiteName -URL $.SiteURL -Owner $.SiteOwner -Template $.SiteTemplate }

    Reference: https://www.sharepointdiary.com/2016/06/create-site-collections-in-bulk-from-csv-using-powershell.html


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Michael Durkan 12,216 Reputation points MVP
    2022-11-30T17:44:22.963+00:00

    Hi

    article below shows how to do this and a sample of how the CSV should be formatted:

    https://www.sharepointdiary.com/2017/09/sharepoint-online-create-multiple-site-collections-in-bulk-from-csv-file-using-powershell.html

    Hope this helps,

    Thanks

    Michael Durkan

    • If the reply was helpful please upvote and/or accept as answer as this helps others in the community with similar questions. Thanks!
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.