Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / Get-LockedChildItem
Created November 23, 2013 20:03
Function to retrieve locked items in the Sitecore CMS.
function Get-LockedChildItem {
<#
.SYNOPSIS
Gets the locked item at the specified location.
.PARAMETER Path
Specifies a path to search for locked items. The default location is the current directory (.).
.PARAMETER LockedBy
Specifies the the owner account locked on the item.
@michaellwest
michaellwest / TDS Package Version Target
Last active December 29, 2015 11:48
Hedgehog Team Development for Sitecore - Package version based on Assembly Version
<Import Project="$(MSBuildExtensionsPath)\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets" />
<ItemGroup>
<AssembliesPath Include="..\SomethingAwesome.Web\bin\SomethingAwesome.Web.dll" />
</ItemGroup>
<Target Name="BeforeSitecoreBuild">
<GetAssemblyIdentity AssemblyFiles="@(AssembliesPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<CreateProperty Value="%(AssemblyVersion.Version)">
<Output TaskParameter="Value" PropertyName="PackageVersion" />
@michaellwest
michaellwest / ReportDuplicateEmployeeID
Created January 17, 2014 17:09
Find users with duplicate employee ids.
# Get all the enabled users.
$users = Get-ADUser -Filter { Enabled -eq $true } -Properties EmployeeId
# Collect all the ids and format them to 7 characters.
$ids = @{}; $users | ForEach-Object { if($_.EmployeeId) { $ids[("{0:D7}" -f [int]$_.EmployeeId)] += 1 } }
$filteredUsers = $users | Where-Object { if($_.EmployeeId) { $ids[("{0:D7}" -f [int]$_.EmployeeId)] -gt 1 } }
$filteredUsers | Select-Object -Property SamAccountName, EmployeeId
$filteredUsers | Export-Csv -Path "C:\temp\DuplicateEmployeeId-$((Get-Date).ToString('yyyyMMddThhmmss')).csv" -NoTypeInformation
@michaellwest
michaellwest / App_Offline.htm.disabled
Last active January 4, 2016 00:49
Site maintenance files for IIS.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Down for Maintenance</title>
</head>
<body>
<div>&nbsp;</div>
<div id="wrapper">
<div id="page">
<div id="content">
@michaellwest
michaellwest / ImageToClipboard.reg
Created January 24, 2014 21:07
Copy the selected image to the clipboard. This allows you to paste the image content into an email or other programs.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\pngfile\shell\Copy image to clipboard]
@="Copy image to clipboard"
[HKEY_CLASSES_ROOT\pngfile\shell\Copy image to clipboard\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -Command \"Add-Type -AssemblyName 'PresentationFramework','PresentationCore';[System.Windows.Clipboard]::SetImage((New-Object System.Windows.Media.Imaging.BitmapImage ([System.Uri]'%1')))\""
[HKEY_CLASSES_ROOT\jpegfile\shell\Copy image to clipboard]
@="Copy image to clipboard"
@michaellwest
michaellwest / UpdateADThumbnail.ps1
Created February 20, 2014 15:01
Update Active Directory thumbnail photo using PowerShell.
Import-Module ActiveDirectory
Set-ADUser -Identity "Michael.West" -Replace @{"thumbnailPhoto" = [byte[]](Get-Content -Path "michael.jpg" -Encoding Byte)}
@michaellwest
michaellwest / UnusedMediaItems.ps1
Last active October 21, 2022 14:09
Sitecore PowerShell script to locate media items without reference to any other item.
<#
.SYNOPSIS
Lists all media items that are not linked to other items.
.NOTES
Michael West
#>
# HasReference determines if the specified item is referenced by any other item.
function HasReference {
@michaellwest
michaellwest / Archive Logs.ps1
Last active August 29, 2015 14:00
Scripts to archive Sitecore log files.
<#
.SYNOPSIS
Archives old log files int zip format to a separate archive directory.
.NOTES
Michael West
#>
<#
Load the function Compress-Archive. The Get-Item command supports a dynamic parameter
@michaellwest
michaellwest / Relink Sitecore Image.ps1
Last active August 3, 2021 07:46
Demonstrates how to relink images using Sitecore PowerShell Extensions. Comment included by Dylan shows how to Remove the link and remove the item.
@michaellwest
michaellwest / ApplicationDetails.cs
Last active August 29, 2015 14:06
Provides reflection methods to extract version details.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
using System.Text;
using Sitecore.SharedSource.Reflection;
using Sitecore.Pipelines.GetAboutInformation;
namespace Sitecore.SharedSource.Pipelines
{
public class ApplicationDetails