Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple script to execute commands against the FillDB page in Sitecore 7.2
# Example of running Invoke-FillDB.ps1
# Additional files to download
$downloads= @(
# Custom template
$template = "{1C7E374B-44FC-4E33-8F8B-857D1A32CDC3}"
# Additional fields on a custom template to populate
$fields= @(
$site = "http://sitecore.testsite"
$username = "sitecore\username"
$password = "password"
# Invoke-FillDB performing all basic steps
$response = .\Invoke-FillDB.ps1 $site $username $password -clearCache -runSqlScript `
-createWordsDir -wordsDir "words" -downloadFiles $downloads -templateFields $fields `
-templateGuid $template -prefix "Standard" `
-wordsPerField 100 -itemCount 100 -indexName "sitecore_master_index"
# See the response
# Invoke-FillDB only creating items
$response = .\Invoke-FillDB.ps1 $site $username $password -itemCount 100 -clearcache
# See the response
Run FillDB.aspx on a Sitecore instance
Processes the FillDB.aspx admin page to create new items in Sitecore
# The full url of the site to run FillDB on
# The user to login as - must have access to FillDb page
# The password of the user
# The database to run content into. Defaults to "master"
$database = "master",
# The directory to create/store/read txt files. Defaults to "/data/words"
$wordsDir = "/data/words",
# Set if the preparation sql script should be ran.
# The sql preparation script. Defaults to "/sitecore/admin/SqlScripts/ItemGenerator.sql"
$sqlScript = "/sitecore/admin/SqlScripts/ItemGenerator.sql",
# Set if the words directory should be initialized
# Set if the cache should be cleared
# A collection of files to download
# The number of items to generate
[int]$itemCount = 0,
# The guid to create items under. Defaults to "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}" (Home)
$parentGuid = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}",
# The template guid to create items based on. Defaults to "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}" (Sample Item)
$templateGuid = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}",
# The fields of the template to populate. Defaults to "{A60ACD61-A6DB-4182-8329-C957982CEC74}","{75577384-3C97-45DA-A847-81B00500E250})" (Title and Text of Sample Item)
[string[]]$templateFields = @("{A60ACD61-A6DB-4182-8329-C957982CEC74}","{75577384-3C97-45DA-A847-81B00500E250}"),
# The prefix to add to the name of created items. Defaults to "Auto"
$prefix = "Auto",
# The maxium number of words to set in a field. Defaults to 25
[int]$wordsPerField = 25,
# Set if the indexes should be rebuilt.
# The index to rebuild after items are inserted.
# The item ids to index from.
Function Get-SitecoreSession{
# Login - to create web session with authorisation cookies
$loginPage = "$site/sitecore/admin/login.aspx"
$login = Invoke-WebRequest $loginPage -SessionVariable webSession
$form = $login.forms[0]
$form.fields["LoginTextBox"] = $username
$form.fields["PasswordTextBox"] = $password
Invoke-WebRequest -Uri $loginPage -WebSession $webSession -Method POST -Body $form | Out-Null
# Parameters to post to fill db page
$body = @{
database = $database
wordsDir = $wordsDir
runsql = $runSqlScript
sqlScript = $sqlScript
runWordsDir = $createWordsDir
runDownloadFiles = $downloadFiles.Count -gt 0
downloadFiles = $downloadFiles -join ","
runCacheClear = $clearCache
runGenerate = $itemCount -gt 0
itemCount = $itemCount
parentGuid = $parentGuid
templateGuid = $templateGuid
templateFields = $templateFields -join ","
namePrefix = $prefix
wordsPerField = $wordsPerField
runIndex = $runIndex -or (-not [string]::IsNullOrEmpty($indexName)) -or ($indexRoots.Length -gt 0)
indexName = $indexName
indexRoots = $indexRoots -join ","
json = $true
$session = Get-SitecoreSession
$fillPage = "$site/sitecore/admin/filldb.aspx"
Invoke-RestMethod -Uri $fillPage -WebSession $session -Method POST -Body $body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment