Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sitecore Touch-Item Powershell Cmdlet
using System.Management.Automation;
using Sitecore.Data.Items;
[OutputType(typeof(Item)), Cmdlet("Touch", "Item")]
public class TouchItem : Cmdlet
{
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public Item Item { get; set; }
protected override void ProcessRecord()
{
if (Item.Database.Name != "master")
{
WriteError(new ErrorRecord(new Exception("Can only touch items in the master database"), "Touch Item", ErrorCategory.InvalidOperation, this));
return;
}
Item.Editing.BeginEdit();
Item[FieldIDs.Revision] = Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture);
Item.Editing.EndEdit(false, false);
Log.Info($"Touched item {Item.Uri}", nameof(TouchItemCommand));
WriteObject(Item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment