Skip to content

Instantly share code, notes, and snippets.

@mikaelnet
Created April 15, 2019 14:23
Show Gist options
  • Save mikaelnet/46e6aaa655ac8b74ee60a0cdc0763c46 to your computer and use it in GitHub Desktop.
Save mikaelnet/46e6aaa655ac8b74ee60a0cdc0763c46 to your computer and use it in GitHub Desktop.
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