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
michaellwest / FindLockedItemsInTheDatabase.ps1
Last active Oct 16, 2019
Find locked items by user using Sitecore PowerShell Extensions. This takes into account which language and version of the items are locked.
View FindLockedItemsInTheDatabase.ps1
Import-Function -Name Invoke-SqlCommand
$owner = "sitecore\admin"
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$fieldId = [Sitecore.FieldIDs]::Lock
$query = @"
SELECT [ItemId], [Value], [Language], [Version]
@michaellwest
michaellwest / SharePoint-AddSelectAll
Created Sep 25, 2019
Adds a select all option to a SharePoint list of checkboxes.
View SharePoint-AddSelectAll
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(function() {
var statesTable = $('table[id^="State"');
var selectAll = $('<a href="#" id="select-all-states">Select All</a>').insertBefore(statesTable);
selectAll.on('click', function(e) {
e.preventDefault();
statesTable.find('.ms-RadioText :checkbox').prop('checked', true);
});
$('<span>&nbsp;</span>').insertBefore(statesTable);
@michaellwest
michaellwest / CleanupBlobData.sql
Created Sep 24, 2019
Cleanup orphaned blob data using SSMS. When Sitecore runs this process it may timeout otherwise.
View CleanupBlobData.sql
DECLARE @BlobID uniqueidentifier;
SELECT @BlobID = '{FF8A2D01-8A77-4F1B-A966-65806993CD31}';
WITH [BlobFields] ([fieldid])
AS (SELECT [sharedfields].[itemid]
FROM [sharedfields]
WHERE [sharedfields].[fieldid] = @BlobID
AND [sharedfields].[value] = 1
UNION
SELECT [versionedfields].[itemid]
@michaellwest
michaellwest / SitecoreRenderingStats.ps1
Created Sep 10, 2019
Duplicates the functionality seen in the Sitecore stats.aspx admin page using Sitecore PowerShell Extensions.
View SitecoreRenderingStats.ps1
$items = [Sitecore.Diagnostics.Statistics]::RenderingStatistics
$props = @{
Property = @(
@{Label="Rendering"; Expression={$_.TraceName} },
@{Label="Site"; Expression={$_.SiteName} },
@{Label="Count"; Expression={$_.RenderCount} },
@{Label="From cache"; Expression={$_.UsedCache} },
@{Label="Avg. time (ms)"; Expression={$_.AverageTime.TotalMilliseconds} },
@{Label="Avg. items"; Expression={$_.AverageItemsAccessed} },
@{Label="Max. time"; Expression={$_.MaxTime.TotalMilliseconds} },
@michaellwest
michaellwest / Remove-Multiple-Sessions.ps1
Created Jul 15, 2019
Remove duplicate user sessions during login using Sitecore PowerShell Extensions. Solution for https://github.com/SitecoreSupport/Sitecore.Support.94909.
View Remove-Multiple-Sessions.ps1
# Solution for https://github.com/SitecoreSupport/Sitecore.Support.94909
# Cannot login in Sitecore CMS due to multiple same users already logged in
# Saved to /sitecore/system/Modules/PowerShell/Script Library/[CUSTOM_MODULE_NAME]/Pipelines/LoggedIn/Remove Multiple Sessions
$pipelineArgs = Get-Variable -Name pipelineArgs -ValueOnly
$username = $pipelineArgs.UserName
if(!$username) { return }
$sessionId = [System.Web.HttpContext]::Current.Session.SessionID
Write-Log "The current session Id is $($sessionId) for user $($username)"
@michaellwest
michaellwest / Report-Template-Sources-Faster.ps1
Last active Jul 11, 2019
Find all template fields where the source is not empty using Sitecore PowerShell Extensions.
View Report-Template-Sources-Faster.ps1
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$path = "/sitecore/templates/Project"
$templateId = "{AB86861A-6030-46C5-B394-E8F99E8B87DB}"
$templateFieldId = "{455A3E98-A627-4B40-8035-E683A0331AC7}"
$db = Get-Database -Name "master"
$rootItem = $db.GetItem($path)
$templates = $rootItem.Axes.GetDescendants() |
Where-Object { $_.TemplateId -eq $templateId } | Initialize-Item
@michaellwest
michaellwest / Update-AltTags.ps1
Created Jul 5, 2019
Update image alt tags using Sitecore PowerShell Extensions.
View Update-AltTags.ps1
$rootPath = "/content/Company/DotCom/usa/home"
$file = "$($SitecoreDataFolder)\temp\alt-tags.csv"
$records = Import-Csv -Path $file
$totalCount = $records.Count
$currentCount = 0
$activity = "Updating alt tags"
foreach($record in $records) {
$currentCount += 1
$percentComplete = $currentCount / $totalCount * 100
$itemPath = $rootPath + ($record.Url -replace "www.Company.com","")
@michaellwest
michaellwest / New-DesktopShortcut.ps1
Last active Jun 20, 2019
Add a new Sitecore Desktop shortcut with Sitecore PowerShell Extensions.
View New-DesktopShortcut.ps1
class DesktopLink {
[string]$DatabaseName
[string]$Path
[string]$Icon
[string]$Header
[string]$Language
[string]ToString(){
$fields = @()
$fields += [System.Web.HttpUtility]::UrlEncode($this.DatabaseName)
@michaellwest
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 {
param(
[item]$Item,
[Sitecore.Sites.SiteContext]$SiteContext
)
$result = New-UsingBlock(New-Object Sitecore.Sites.SiteContextSwitcher $siteContext) {
New-UsingBlock(New-Object Sitecore.Data.DatabaseSwitcher $item.Database) {
[Sitecore.Links.LinkManager]::GetItemUrl($item)
}
@michaellwest
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]@{
You can’t perform that action at this time.