Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created October 30, 2018 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/0701440884e0a2289351941ced594979 to your computer and use it in GitHub Desktop.
Save michaellwest/0701440884e0a2289351941ced594979 to your computer and use it in GitHub Desktop.
Create a random set of items using Sitecore PowerShell Extensions.
$selectedRootItem = Get-Item -Path "master:" -ID "{A1D0B3BC-CCDA-41FF-B59A-33AB84BF950B}"
$selectedItemTemplate = Get-Item -Path "master:" -ID "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
$inputCount = 100
$itemNamePrefix = "DeleteMe"
$childCount = $selectedrootItem.Children.Count + 1
$createdItems = [System.Collections.ArrayList]@()
$totalItemCount = $childCount + $inputCount
for($index = $childCount; $index -lt $totalItemCount; $index++) {
$createdItem = $null
if($index -lt 10 -or $index % 50 -eq 0) {
$createdItem = New-Item -Path $selectedrootItem.ProviderPath -Name "$($itemNamePrefix)$($index)" -Type $selectedItemTemplate.Paths.Path
$createdItems.Add($createdItem) > $null
} else {
$randomIndex = Get-Random -Minimum 0 -Maximum ($createdItems.Count - 1)
$rootItemPath = $createdItems[$randomIndex].ProviderPath
$createdItem = New-Item -Path $rootItemPath -Name "$($itemNamePrefix)$($index)" -Type $selectedItemTemplate.Paths.Path
$createdItems.Add($createdItem) > $null
}
Write-Progress -Activity "Creating new items" -Status "Created $($createdItem.ProviderPath)" -PercentComplete ($index/$totalItemCount*100)
}
Write-Progress -Completed -Activity "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment