Sitecore is built from the grounds up with extendibility in mind. Be that plugging into any place in its internal pipelines or any aspect of its User eXperience, therefore when I’ve managed to extend it’s context menu, I expected to have no problems whatsoever doing the same to its ribbon. Mind you I was right…

Using the PowerShell Console Module it took me less than 10 minutes total to add a nice piece of functionality that I thought was missing – Publish items I have modified.

ContextScriptsRibbon

Similarly to extending context menu – first I’ve created the script I wanted to execute that will take the current item and it’s sub-items and publish them by adding a new script item using the /sitecore/templates/Cognifide/PowerShell Script template in the core database. I’ve put it in the same place I store all my my scripts – in the /sitecore/content/Applications/PowerShell Console/Scripts branch but feel free to store them anywhere in the tree.

  • Filled in the Script body part with my script.
  • I decided I want to see the publishing results as I want to verify if the items I expected got published.

ContextScriptRibbonBody

Now the UI integration bits…

Since I wanted it nicely integrated with the publish button – I’ve created a Publish My Items item of template /sitecore/templates/System/Menus/Menu item within the /sitecore/content/Applications/Content Editor/Menues/Publish/ branch in the core database, set it’s icon and reference the script item in the Message field using the following pattern:

item:executescript(id=$Target,script={0937769B-998D-4580-B9FE-730C4CDABECD},scriptDb=core)

where the script guid is the ID of your script and the scriptDb is the database the script is located in.

ContextScriptsRibbonBinding

That’s it really. You can download the solution but I would strongly recommend you try the manual approach – it’s really exciting to see the puzzles click in.

The solution requires the Sitecore PowerShell Console from Cognifide, available for free from Sitecore Shared Source site.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...



This entry (Permalink) was posted on Thursday, November 24th, 2011 at 11:08 am and is filed under .Net Framework, ASP.NET, C#, Code Samples, Downloadable, PowerShell, Sitecore, Software, Software Development, Solution, Web applications. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response , or trackback from your own site.



  • Pingback: Continuous deployment in Sitecore with PowerShell | Codality()

  • Pingback: Your own PowerShell commandlets | Codality()

  • J.Baltika

    Hi Adam, I am newbie in to PowerShell and getting this error on Win2008 server, but some your scripts work fine (user activity) No idea how to fix and where to start:
    The following error occurred while loading the extended type data file: Microsoft.PowerShell, C:developmentDemo-ServersDemo-sitecore-contentservertrunkwebsiteConsoleAssetsSitecore.Types.ps1xml : File skipped because of the following validation exception: File C:developmentDemo-ServersDemo-sitecore-contentservertrunkwebsiteConsoleAssetsSitecore.Types.ps1xml cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details..There were errors in loading the format data file: Microsoft.PowerShell, , C:developmentDemo-ServersDemo-sitecore-contentservertrunkwebsiteConsoleAssetsSitecore.Views.ps1xml : File skipped because of the following validation exception: File C:developmentDemo-ServersDemo-sitecore-contentservertrunkwebsiteConsoleAssetsSitecore.Views.ps1xml cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details..writeErrorStream      : TrueException             : System.UnauthorizedAccessException: Access to the path ‘C:windowssystem32inetsrvconfig’ is denied.                           at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)                           at System.IO.FileSystemEnumerableIterator`1.CommonInit()                           at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler                        )                           at System.IO.DirectoryInfo.InternalGetDirectories(String searchPattern, SearchOption searchOption)                           at Microsoft.PowerShell.Commands.FileSystemProvider.Dir(DirectoryInfo directory, Boolean recurse, Boolean nameOnly, ReturnContainers returnContainers)TargetObject          : C:windowssystem32inetsrvconfigCategoryInfo          : PermissionDenied: (C:windowssystem32inetsrvconfig:String) [Get-ChildItem], UnauthorizedAccessExceptionFullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommandErrorDetails          :InvocationInfo        : System.Management.Automation.InvocationInfoPipelineIterationInfo : {0, 1, 131, 0}PSMessageDetails      :writeErrorStream      : TrueException             : System.UnauthorizedAccessException: Access to the path ‘C:windowssystem32inetsrvHistory’ is denied.                           at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)                           at System.IO.FileSystemEnumerableIterator`1.CommonInit()                           at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler                        )                           at System.IO.DirectoryInfo.InternalGetDirectories(String searchPattern, SearchOption searchOption)                           at Microsoft.PowerShell.Commands.FileSystemProvider.Dir(DirectoryInfo directory, Boolean recurse, Boolean nameOnly, ReturnContainers returnContainers)TargetObject          : C:windowssystem32inetsrvHistoryCategoryInfo          : PermissionDenied: (C:windowssystem32inetsrvHistory:String) [Get-ChildItem], UnauthorizedAccessExceptionFullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommandErrorDetails          :InvocationInfo        : System.Management.Automation.InvocationInfoPipelineIterationInfo : {0, 1, 178, 0}PSMessageDetails      :writeErrorStream      : TrueException             : System.UnauthorizedAccessException: Access to the path ‘C:windowssystem32inetsrvMetaBack’ is denied.                           at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)                           at System.IO.FileSystemEnumerableIterator`1.CommonInit()                           at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler                        )                           at System.IO.DirectoryInfo.InternalGetDirectories(String searchPattern, SearchOption searchOption)                           at Microsoft.PowerShell.Commands.FileSystemProvider.Dir(DirectoryInfo directory, Boolean recurse, Boolean nameOnly, ReturnContainers returnContainers)TargetObject          : C:windowssystem32inetsrvMetaBackCategoryInfo          : PermissionDenied: (C:windowssystem32inetsrvMetaBack:String) [Get-ChildItem], UnauthorizedAccessExceptionFullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommandErrorDetails          :InvocationInfo        : System.Management.Automation.InvocationInfoPipelineIterationInfo : {0, 1, 181, 0}PSMessageDetails      :

  • hi J.
    Sorry for the late reply, I wasn’t checking the blog recently.The first problem I see is that you have script files execution disabled on your system. as suggested on the error message you can learn more about it by typing: “get-help about_signing” and enable script files execution by running “Set-ExecutionPolicy RemoteSigned” in an elevated privileges PowerShell console on your server’s desktop.

    Then there is the real problem which is:UnauthorizedAccessException: Access to the path ‘C:windowssystem32inetsrvconfig’ is denied – which means the script you were executing tried to do something with files located in “C:windowssystem32inetsrvconfig”. This is probably due to the fact that the script didn’t switch to the Sitecore content drive e.g. “cd master:” before attempting to do it’s job.

    Hope it helps… despite the delay.

  • Pingback: Sitecore PowerShell Extensions Persistent Sessions | Codality()