Scenario:
Wanted to do a load test on Record Center with my custom solution. I wanted to have 100 record libraries with 100 folder each.
Solution:
Powershell script can do it in few minutes
Code:
clear Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.Powershell [Void][System.Diagnostics.Stopwatch] $sw; # New Stopwatch object $sw = New-Object System.Diagnostics.StopWatch; # Stop any watches that might be running $sw.Stop(); $sw.Start(); # Initialization $webUrl = 'http://recordcenter' $libCount = 1; $folderCount = 1; $libraryName = "Record Library" + $libCount $frontSlash = "/" $web = Get-SPWeb $webUrl; $listTemplate = $web.ListTemplates | Where-Object {$_.Name -eq "Record Library"} #Create folders (1..100)|%{ $libraryName = "Contract Library" + $libCount write-host "Creating Record library: " $libraryName $web.Lists.Add($libraryName,"Record Library",$listTemplate); $libCount = $libCount + 1; [string]$howlong0 = $sw.Elapsed.ToString(); # How long Write-Host "Library Ready (Time ): " $howlong0 -F Green; $spDocumentLibrary = $web.Lists.TryGetList($libraryName) (1..1000)|%{ write-host "Adding Folder in library: " $libraryName $folderName = "Folder" + $folderCount $spFolder = $spDocumentLibrary.AddItem("",[Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$folderName) $spFolder.Update() $folderCount = $folderCount+1 [string]$howlong0 = $sw.Elapsed.ToString(); # How long Write-Host "Folder Ready (Time ): " $howlong0 -F Green; } } $web.Dispose() $sw.Stop(); # Stop the timer [string]$howlong = $sw.Elapsed.ToString(); # How long write-host "Done (Time ): " $howlong -F Green;
0 comments:
Post a Comment