Created
April 15, 2019 14:23
-
-
Save mikaelnet/46e6aaa655ac8b74ee60a0cdc0763c46 to your computer and use it in GitHub Desktop.
Sitecore Touch-Item Powershell Cmdlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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