Summary
This is my 2nd version of SharePoint Population Script with a few minor changes.
- Removed the Hosts file and host header creation to simplify the process.
- The new script will only create a single DB.
- A new Web Application using the server host name over a different port is now allowed.
- A Modern Team Site will be created.
What is looks like
Here is an example of running the script:


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
How many Sites should be created?: 2 How many Lists should be created?: 5 How many Items in each list?: 10 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: spwfe Enter your SQL Server Name: sql Name of the new Content DB: wss_content_Test_db2 Enter the SP Managed Account. Example: contoso\spadmin: contoso\spservice Enter a name for the new Web App: WebApp Test2 What port number do you want to use?: 6000 Enter a name for the new AppPool: WebApp-Test2-AppPool Is this a 2010 Farm Y/N?: N The new Web Application spwfe is being created. Please stand by... The new Content Database wss_content_Test_db2 is being created. Please stand by... The new Root Site http://spwfe:6000 is being created. Please stand by... Url CompatibilityLevel --- ------------------ http://spwfe:6000 15 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 : aa53a958-10f6-4d99-95a5-00c1c369be00 #################################### List 1 created in http://spwfe:6000 #################################### 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 ############################## Item: 6 created in list: 1 ############################## Item: 7 created in list: 1 ############################## Item: 8 created in list: 1 ############################## Item: 9 created in list: 1 ############################## Item: 10 created in list: 1 ############################## Guid : 7ad3241e-3d9a-4a5b-b81f-d66fd458ef5e #################################### List 2 created in http://spwfe:6000 #################################### 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 ############################## Item: 6 created in list: 2 ############################## Item: 7 created in list: 2 ############################## Item: 8 created in list: 2 ############################## Item: 9 created in list: 2 ############################## Item: 10 created in list: 2 ############################## Guid : b033583e-bd9b-49a0-9eb3-63c40f843582 #################################### List 3 created in http://spwfe:6000 #################################### Item: 1 created in list: 3 ############################## Item: 2 created in list: 3 ############################## Item: 3 created in list: 3 ############################## Item: 4 created in list: 3 ############################## Item: 5 created in list: 3 ############################## Item: 6 created in list: 3 ############################## Item: 7 created in list: 3 ############################## Item: 8 created in list: 3 ############################## Item: 9 created in list: 3 ############################## Item: 10 created in list: 3 ############################## Guid : a5da8fb0-a7c6-4f1e-ba8d-79cf79b73044 #################################### List 4 created in http://spwfe:6000 #################################### Item: 1 created in list: 4 ############################## Item: 2 created in list: 4 ############################## Item: 3 created in list: 4 ############################## Item: 4 created in list: 4 ############################## Item: 5 created in list: 4 ############################## Item: 6 created in list: 4 ############################## Item: 7 created in list: 4 ############################## Item: 8 created in list: 4 ############################## Item: 9 created in list: 4 ############################## Item: 10 created in list: 4 ############################## Guid : 8f2468cb-107f-44a8-872b-6a49f925ba72 #################################### List 5 created in http://spwfe:6000 #################################### Item: 1 created in list: 5 ############################## Item: 2 created in list: 5 ############################## Item: 3 created in list: 5 ############################## Item: 4 created in list: 5 ############################## Item: 5 created in list: 5 ############################## Item: 6 created in list: 5 ############################## Item: 7 created in list: 5 ############################## Item: 8 created in list: 5 ############################## Item: 9 created in list: 5 ############################## Item: 10 created in list: 5 ############################## #################### Creating Sub Site 1 #################### Guid : 59247c47-36d5-402f-9f55-53009b7e3677 ######################################## List 1 created in http://spwfe:6000/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 ################################ Item: 6 created in list: 1 ################################ Item: 7 created in list: 1 ################################ Item: 8 created in list: 1 ################################ Item: 9 created in list: 1 ################################ Item: 10 created in list: 1 ################################ Guid : b2176570-ed99-4d0b-a1cf-4cdb54762141 ######################################## List 2 created in http://spwfe:6000/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 ################################ Item: 6 created in list: 2 ################################ Item: 7 created in list: 2 ################################ Item: 8 created in list: 2 ################################ Item: 9 created in list: 2 ################################ Item: 10 created in list: 2 ################################ Guid : 0b271e12-7fb0-48e3-82a2-dcaa7c628df5 ######################################## List 3 created in http://spwfe:6000/1 ######################################## Item: 1 created in list: 3 ################################ Item: 2 created in list: 3 ################################ Item: 3 created in list: 3 ################################ Item: 4 created in list: 3 ################################ Item: 5 created in list: 3 ################################ Item: 6 created in list: 3 ################################ Item: 7 created in list: 3 ################################ Item: 8 created in list: 3 ################################ Item: 9 created in list: 3 ################################ Item: 10 created in list: 3 ################################ Guid : 65b36498-b429-405a-a86f-9e38be56eb5c ######################################## List 4 created in http://spwfe:6000/1 ######################################## Item: 1 created in list: 4 ################################ Item: 2 created in list: 4 ################################ Item: 3 created in list: 4 ################################ Item: 4 created in list: 4 ################################ Item: 5 created in list: 4 ################################ Item: 6 created in list: 4 ################################ Item: 7 created in list: 4 ################################ Item: 8 created in list: 4 ################################ Item: 9 created in list: 4 ################################ Item: 10 created in list: 4 ################################ Guid : 17b22a0e-aaa9-47b5-9d6f-f702110d9620 ######################################## List 5 created in http://spwfe:6000/1 ######################################## Item: 1 created in list: 5 ################################ Item: 2 created in list: 5 ################################ Item: 3 created in list: 5 ################################ Item: 4 created in list: 5 ################################ Item: 5 created in list: 5 ################################ Item: 6 created in list: 5 ################################ Item: 7 created in list: 5 ################################ Item: 8 created in list: 5 ################################ Item: 9 created in list: 5 ################################ Item: 10 created in list: 5 ################################ #################### Creating Sub Site 2 #################### Creating document: /2/Shared Documents/TestDocument1.csv ... Creating document: /2/Shared Documents/TestDocument2.csv ... Creating document: /2/Shared Documents/TestDocument3.csv ... Creating document: /2/Shared Documents/TestDocument4.csv ... Creating document: /2/Shared Documents/TestDocument5.csv ... Guid : 9b5e80ef-ccde-42af-a5d6-e2365e79dfcf ######################################## List 1 created in http://spwfe:6000/2 ######################################## 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 ################################ Item: 6 created in list: 1 ################################ Item: 7 created in list: 1 ################################ Item: 8 created in list: 1 ################################ Item: 9 created in list: 1 ################################ Item: 10 created in list: 1 ################################ Guid : 34cc51c3-cccd-49b6-b252-9fe1fc5c6c3c ######################################## List 2 created in http://spwfe:6000/2 ######################################## 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 ################################ Item: 6 created in list: 2 ################################ Item: 7 created in list: 2 ################################ Item: 8 created in list: 2 ################################ Item: 9 created in list: 2 ################################ Item: 10 created in list: 2 ################################ Guid : b1facba1-93ff-44da-9e7f-a0d3e81d118f ######################################## List 3 created in http://spwfe:6000/2 ######################################## Item: 1 created in list: 3 ################################ Item: 2 created in list: 3 ################################ Item: 3 created in list: 3 ################################ Item: 4 created in list: 3 ################################ Item: 5 created in list: 3 ################################ Item: 6 created in list: 3 ################################ Item: 7 created in list: 3 ################################ Item: 8 created in list: 3 ################################ Item: 9 created in list: 3 ################################ Item: 10 created in list: 3 ################################ Guid : 747d479d-fbec-4e4c-94d1-7ef34f0ee6b1 ######################################## List 4 created in http://spwfe:6000/2 ######################################## Item: 1 created in list: 4 ################################ Item: 2 created in list: 4 ################################ Item: 3 created in list: 4 ################################ Item: 4 created in list: 4 ################################ Item: 5 created in list: 4 ################################ Item: 6 created in list: 4 ################################ Item: 7 created in list: 4 ################################ Item: 8 created in list: 4 ################################ Item: 9 created in list: 4 ################################ Item: 10 created in list: 4 ################################ Guid : 0ffd5646-710c-4d84-818f-8a4a4c8f36cc ######################################## List 5 created in http://spwfe:6000/2 ######################################## Item: 1 created in list: 5 ################################ Item: 2 created in list: 5 ################################ Item: 3 created in list: 5 ################################ Item: 4 created in list: 5 ################################ Item: 5 created in list: 5 ################################ Item: 6 created in list: 5 ################################ Item: 7 created in list: 5 ################################ Item: 8 created in list: 5 ################################ Item: 9 created in list: 5 ################################ Item: 10 created in list: 5 ################################ ########################################## Your Site population script has completed! ########################################## |

The Script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# Load Microsoft.SharePoint.PowerShell Add-PSSnapin Microsoft.SharePoint.Powershell -ea 0 #Script Parameters $sitecount = (Read-Host "How many Sites should be created?") $listcount = (Read-Host "How many Lists should be created?") $itemcount = (Read-Host "How many Items in each list?") $doccount = (Read-Host "How many Documents should be created?") $url = (Read-Host "Specify the full URL of the new SharePoint Site, without http://. Example: contoso, contoso.local or www.contoso.com") $sqlsvr = (Read-Host "Enter your SQL Server Name") $sqldb = (Read-Host "Name of the new Content DB") $siteowner = (Read-Host "Enter the SP Managed Account. Example: contoso\spadmin") $sitename = (Read-Host "Enter a name for the new Web App") $port = (Read-Host "What port number do you want to use?") $apppool = (Read-Host "Enter a name for the new AppPool") $is2010 = (Read-Host "Is this a 2010 Farm Y/N?") #Adding 2010 capability if ($is2010 -eq "Y"){ $docLibraryName = "Shared Documents" } if ($is2010 -eq "N"){ $docLibraryName = "Documents" } #Static Settings $sourceDocumentPath = "$env:TEMP\temp\TestDocument.csv" $newFilenamePrefix = "TestDocument" $newFilenameExtension = ".csv" $hostsfile = "$env:windir\System32\drivers\etc\hosts" $spaccount = (Get-SPManagedAccount $siteowner) $user2 = whoami ################################## #Root WEB Creation and Population# ################################## #Create the new web app Write-Host "The new Web Application $url is being created. Please stand by..." -ForegroundColor Green $site = "http://" + $url + ":" + $port $webapp = New-SPWebApplication -Name $sitename -URL $site -ApplicationPool $apppool -ApplicationPoolAccount $spaccount -DatabaseServer $sqlsvr -DatabaseName $sqldb #Create a new Content Database Write-Host "The new Content Database $sqldb is being created. Please stand by..." -ForegroundColor Yellow #Create Root Site Write-Host "The new Root Site $site is being created. Please stand by..." -ForegroundColor Yellow $SiteTemplate = "STS#3" #Modern Team Site $Language = 1033 New-SPSite -Url $site -OwnerAlias $siteowner -SecondaryOwnerAlias $user2 -Template $SiteTemplate -Language $Language -ContentDatabase $sqldb ################################## #Population Root Web# ################################## #Test file creation #make a new folder if it does not exist $TARGETDIR = "$env:TEMP\temp" if(!(Test-Path -Path $env:TEMP\temp)){ New-Item -ItemType directory -Path $TARGETDIR } dir | export-csv "$env:TEMP\temp\TestDocument.csv" #defining WEB $web = Get-SPWeb $site #Create Documents $docLibrary = $web.Lists[$docLibraryName] $docLibraryUrl = $docLibrary.RootFolder.ServerRelativeUrl $folderPathWithinDocLibrary = "" $uploadfolder = $web.getfolder($docLibraryUrl + $folderPathWithinDocLibrary) #Open file $file = get-item $sourceDocumentPath $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead() #Starting loop create docs in Root Library for($d=1; $d -le $doccount; $d++) { $newFilePath = $docLibraryUrl + $folderPathWithinDocLibrary + "/" + $newFilenamePrefix+$d+$newFilenameExtension write-host "Creating document: $newFilePath ..." -ForegroundColor Yellow $spFile = $uploadfolder.Files.Add($newFilePath, [System.IO.Stream]$fileStream, $true) } #Start Loop for List creation based on $listcount in ROOT Library for($l=1; $l -le $listcount; $l++) #Create the Lists { $ListTemplate = $web.ListTemplates["Custom List"] $web.Lists.Add("List $l","List $l",$listTemplate) Write-Host "####################################" -ForegroundColor Green write-host "List $l created in $site" -ForegroundColor Green Write-Host "####################################" -ForegroundColor Green # While creating lists put new items in it based on the $itemcount if ($l -le $listcount ) { #Start Loop for List Item creation in ROOT Library for ($i=1; $i -le $itemcount; $i++) { #Create List Item $list = $web.Lists["List $l"] $newItem = $list.AddItem() $newItem["Title"] = "Item $i" $newItem.Update() write-host "Item: $i created in list: $l" -ForegroundColor Yellow Write-Host "##############################" -ForegroundColor Yellow }}} ################################# #Sub WEB Creation and Population# ################################# #Start Loop for site creation for($s=1; $s -le $sitecount ; $s++) { $SiteUrl = "" $SiteUrl = $Site + "/" $SiteUrl = $SiteUrl += $s #Create Webs based on $sitecount Write-Host "####################" -ForegroundColor Yellow Write-Host "Creating Sub Site $s" -ForegroundColor Yellow Write-Host "####################" -ForegroundColor Yellow New-SPWeb $SiteUrl -Template $SiteTemplate -Name $s -UseParentTopNav -Language $Language $web = Get-SPWeb $SiteUrl #Create Documents $docLibrary = $web.Lists[$docLibraryName] $docLibraryUrl = $docLibrary.RootFolder.ServerRelativeUrl $folderPathWithinDocLibrary = "" $uploadfolder = $web.getfolder($docLibraryUrl + $folderPathWithinDocLibrary) #Open file $file = get-item $sourceDocumentPath $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead() #Starting loop to create docs in Library for($d=1; $d -le $doccount; $d++) { $newFilePath = $docLibraryUrl + $folderPathWithinDocLibrary + "/" + $newFilenamePrefix+$d+$newFilenameExtension write-host "Creating document: $newFilePath ..." -ForegroundColor Yellow $spFile = $uploadfolder.Files.Add($newFilePath, [System.IO.Stream]$fileStream, $true) } #Start Loop for List creation based on $listcount for($l=1; $l -le $listcount; $l++) #Create the Lists { $ListTemplate = $web.ListTemplates["Custom List"] $web.Lists.Add("List $l","List $l",$listTemplate) Write-Host "########################################" -ForegroundColor Green write-host "List $l created in $SiteUrl" -ForegroundColor Green Write-Host "########################################" -ForegroundColor Green #Populate list items based on the $itemcount if ($l -le $listcount ) { #Start Loop for List Item creation for ($i=1; $i -le $itemcount; $i++) { #Create List Item $list = $web.Lists["List $l"] $newItem = $list.AddItem() $newItem["Title"] = "Item $i" $newItem.Update() write-host "Item: $i created in list: $l" -ForegroundColor Yellow Write-Host "################################" -ForegroundColor Yellow }}}} #Close file stream $fileStream.Close() #Dispose web $web.Dispose() Write-Host "##########################################" -ForegroundColor Green write-host "Your Site population script has completed!" -ForegroundColor Green Write-Host "##########################################" -ForegroundColor Green |