SharePoint Site Population Script for Testing

Summary

The following script will create and populate data in a SharePoint Farm for testing.

What does the Script do?

  1. Create a new web application, with a new web application pool.
  2. Create new database and associate it with the new web application.
  3. Update the local HOSTS file to make the new site accessible from the server.
  4. Create a Root Site in the new web application.
  5. Create a Test document and store it in the local temp folder.
  6. Populate the default “Document Library” in the root site with the number of documents specified.
  7. Create new lists in the root site based on the number of lists specified.
  8. Populate each list in the root site with the number of items specified.
  9. Create new sub sites based on the amount specified.
  10. Populate the default “Document Library” in all sub sites with the number of documents specified.
  11. Create new lists in each sub site based on the number of lists specified.
  12. Populate each list in all sub sites with the number of items specified.

Important Notes:

  • Since this script will update your local HOSTS file you will need to run PowerShell as Administrator.
  • DisableLoopBackCheck may be required if you access the site locally from the server.

reg.exe add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa /v DisableLoopBackCheck /t REG_DWORD /d 1 /f

Example:

How many Sites should be created?: 1
How many Lists should be created?: 2
How many Items in each list?: 5
How many Documents should be created?: 5
Specify the full URL of the new SharePoint Site, without http://. Example: contoso, contoso.local or www.contoso.com: sptest2
Enter your SQL Server Name: michlee-sql
Name of the new Content DB: sptest2_content_db
Enter the SP Managed Account. Example: contoso\spadmin: mylab\spservice
Enter a name for the new Web App: SPTest2 Web App
Enter a name for the new AppPool: sptest2apppool
The new Web Application sptest2 is being created. Please stand by…
The new Content Database sptest2_content_db is being created. Please stand by…
Id : eb6f2c05-e7d8-491a-9b6f-0a17b2624c65
Name : sptest2_content_db
WebApplication : SPWebApplication Name=SPTest2 Web App
Server : michlee-sql
CurrentSiteCount : 0
127.0.0.1 sptest2
The new Root Site http://sptest2 is being created. Please stand by…
Creating document: /Shared Documents/TestDocument1.csv …
Creating document: /Shared Documents/TestDocument2.csv …
Creating document: /Shared Documents/TestDocument3.csv …
Creating document: /Shared Documents/TestDocument4.csv …
Creating document: /Shared Documents/TestDocument5.csv …
Guid : 5dd9162c-08bd-4fd1-8079-6c3e106386c8
##################################
List 1 created in http://sptest2/
#################################
Item: 1 created in list: 1
################################
Item: 2 created in list: 1
################################
Item: 3 created in list: 1
################################
Item: 4 created in list: 1
################################
Item: 5 created in list: 1
################################
Guid : c81edcd1-71d4-427a-8cd6-a0015a712149
##################################
List 2 created in http://sptest2/
##################################
Item: 1 created in list: 2
################################
Item: 2 created in list: 2
################################
Item: 3 created in list: 2
################################
Item: 4 created in list: 2
################################
Item: 5 created in list: 2
################################
####################
Creating Sub Site 1
####################
Creating document: /1/Shared Documents/TestDocument1.csv …
Creating document: /1/Shared Documents/TestDocument2.csv …
Creating document: /1/Shared Documents/TestDocument3.csv …
Creating document: /1/Shared Documents/TestDocument4.csv …
Creating document: /1/Shared Documents/TestDocument5.csv …
Guid : 585c9288-d72a-472d-8532-5a3139537777
##################################
List 1 created in http://sptest2/1
##################################
Item: 1 created in list: 1
################################
Item: 2 created in list: 1
################################
Item: 3 created in list: 1
################################
Item: 4 created in list: 1
################################
Item: 5 created in list: 1
################################
Guid : a49c9124-de8f-4174-bd12-3958ec1fd62b
###################################
List 2 created in http://sptest2/1
###################################
Item: 1 created in list: 2
################################
Item: 2 created in list: 2
################################
Item: 3 created in list: 2
################################
Item: 4 created in list: 2
################################
Item: 5 created in list: 2
################################
##########################################
Your Site population script has completed!
##########################################

The Script

Leave a Reply