Skip to content

Instantly share code, notes, and snippets.

Michael michaellwest

  • Texas
Block or report user

Report or block michaellwest

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
michaellwest / New-DesktopShortcut.ps1
Last active Jun 18, 2019
Add a new Sitecore Desktop shortcut with Sitecore PowerShell Extensions.
View New-DesktopShortcut.ps1
class DesktopLink {
$fields = @()
$fields += [System.Web.HttpUtility]::UrlEncode($this.DatabaseName)
michaellwest / Get-ItemUrl.ps1
Created Feb 13, 2019
Generate an item url given an item and the sitecontext using Sitecore PowerShell Extensions.
View Get-ItemUrl.ps1
function Get-ItemUrl {
$result = New-UsingBlock(New-Object Sitecore.Sites.SiteContextSwitcher $siteContext) {
New-UsingBlock(New-Object Sitecore.Data.DatabaseSwitcher $item.Database) {
michaellwest / FindFieldsWithChangeFromStandardValues.ps1
Last active Jan 9, 2019
Find all the fields for an item where the standard value has been changed using Sitecore PowerShell Extensions.
View FindFieldsWithChangeFromStandardValues.ps1
# Find all fields where there is a standard value defined and is not the same as the current value
$item = Get-Item -Path "master:" -ID "{DFDDF372-3AB7-45B1-9E7C-0D0B27350439}"
# Since $item.Fields.ReadAll() is not called, you never get back fields using the StandardValue
$results = [System.Collections.ArrayList]@()
foreach($field in $item.Fields) {
$standardValue = $field.GetStandardValue()
if([string]::IsNullOrEmpty($standardValue)) { continue }
$value = $field.Value
if($standardValue -eq $value) { continue }
$result = [PSCustomObject]@{
michaellwest / GetAllUsers-Pagination.ps1
Created Jan 5, 2019
Query users in page increments using Sitecore PowerShell Extensions.
View GetAllUsers-Pagination.ps1
$totalCount = 0
$page = 0
$pageSize = 25
$foundCount = 0
while(($users = [System.Web.Security.Membership]::GetAllUsers($page, $pageSize, [ref]$totalCount))) {
Write-Host "Getting users"
$foundCount += $users.Count
if($foundCount -ge $totalCount) {
Write-Host "Done"
michaellwest / 01-New-AccessRuleList.ps1
Last active Dec 27, 2018
Configure security for a tenant built with SXA using Sitecore PowerShell Extensions.
View 01-New-AccessRuleList.ps1
$allowItemProps = @{
PropagationType = [Sitecore.Security.AccessControl.PropagationType]::Entity
SecurityPermission = [Sitecore.Security.AccessControl.SecurityPermission]::AllowAccess
$allowDescendantsProps = @{
PropagationType = [Sitecore.Security.AccessControl.PropagationType]::Descendants
SecurityPermission = [Sitecore.Security.AccessControl.SecurityPermission]::AllowAccess
michaellwest / BulkCreateItemsWithScriptSessions.ps1
Created Nov 27, 2018
Example comparing the time required to create a bunch of items using Sitecore PowerShell Extensions. Creating script sessions appear to be faster.
View BulkCreateItemsWithScriptSessions.ps1
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$sessions = [System.Collections.ArrayList]@()
foreach($i in 1..100) {
$sesh = Start-ScriptSession -ScriptBlock {
New-Item -Path "master:/content/Home/Sample Item" -Name "Sample-$($name)" -ItemType "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}" > $null
} -ArgumentList @{"name"=[ID]::NewID.ToShortID().ToString()} -AutoDispose
$sessions.Add($sesh) > $null
michaellwest / BulkLoadItems-DataBlaster.ps1
Last active Nov 15, 2018
Bulk load Sitecore items using Sitecore.DataBlaster and Sitecore PowerShell Extensions.
View BulkLoadItems-DataBlaster.ps1
$db = Get-Database -Name "master"
$item = $db.GetItem("/sitecore/content/Home/Delete Me")
$template = [Sitecore.Data.Managers.TemplateManager]::GetTemplate("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", $db)
$bulkLoader = New-Object Sitecore.DataBlaster.Load.BulkLoader
$context = $bulkLoader.NewBulkLoadContext($db.Name)
$action = [Sitecore.DataBlaster.Load.BulkLoadAction]::Update
michaellwest / FindItemsWithDuplicateItemPaths
Last active Nov 7, 2018
Find all items under the home item with duplicate item paths using Sitecore PowerShell Extensions.
View FindItemsWithDuplicateItemPaths
$rootId = "{47982199-5497-49DE-8F2D-B10607B5049D}"
$rootItem = Get-Item -Path "master:" -ID $rootId
$rootItem.Axes.GetDescendants() | Initialize-Item |
Group-Object { $_.ItemPath} |
Where-Object { $_.Count -gt 1 } |
Sort-Object -Property Count -Descending |
Select-Object -Property Count, Name
michaellwest / 00-UnicornFastQueryWarning.txt
Last active Nov 5, 2018
Example to override the EnvironmentSiteResolver included with Sitecore Experience Accelerator (SXA).
View 00-UnicornFastQueryWarning.txt
44644 13:45:34 WARN [Unicorn] A Fast Query was performed and Unicorn had one or more configurations enabled that used Transparent Sync. Fast Query is not supported with Transparent Sync. Either stop using Fast Query (it's generally regarded as a bad idea in almost every circumstance), or disable Transparent Sync for all configurations.
44644 13:45:34 WARN [Unicorn] The Fast Query was: //*[@@templateid = '{EDA823FC-BC7E-4EF6-B498-CD09EC6FDAEF}']
44644 13:45:34 WARN [Unicorn] The call stack that made the Fast Query was: at Unicorn.Data.DataProvider.UnicornSqlServerDataProvider.QueryFast(String query, CallContext context)
at Sitecore.Data.DataProviders.DataProvider.SelectIDs(String query, CallContext context, DataProviderCollection providers)
at Sitecore.Data.DataManager.SelectItems(String query, Boolean& processed)
at Sitecore.Data.DataManager.SelectItems(String query)
at Sitecore.Data.DefaultDatabase.SelectItems(String query)
at Scms.Foundation.Multisite.SiteResolvers.ScmsEnvironmentSitesR
michaellwest / RandomItemGenerator.ps1
Created Oct 30, 2018
Create a random set of items using Sitecore PowerShell Extensions.
View RandomItemGenerator.ps1
$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
You can’t perform that action at this time.