5

So, I've been successful in creating a powershell script that modifies the MyToolbar to what we need based on the user's domain:

$ribbonCommands = "{1DDBC2B7-69B4-44A0-AAF9-895AB51B1F00}|{D87FDF3B-D203-4F2F-81A3-14D4701BAEF6}|{D4E9CE87-84D1-42E4-9B8B-55A99605EA82}|{EDA2F1DC-0412-45B2-9FDD-0700B03F28CB}|{1CC9896C-5D20-4439-8938-57B5BFB3734F}|{EDA2F1DC-0412-45B2-9FDD-0700B03F28CB}|{AE7CA3FB-770F-43A9-8BD9-B0E67090DD61}|{CF377B94-17EE-4D82-86B4-419A8B41901A}"

$user = Get-User -Filter "mydomain\*"

$user | ForEach-Object {  
    $prefix = "/"
    $username = $($_.Name)
    $suffix = "/Ribbon/My Strip"
    $registrykey = ${prefix} + ${username} + ${suffix}
    Write-Host $registrykey
    [Sitecore.Web.UI.HtmlControls.Registry]::SetValue($registrykey, $ribbonCommands)
}

This works well for the bulk of users who are now on the system, however, what I want to do is run something like this but a) when a new user is created, and b) grabbing that username so that I can set the values of the MyToolbar for that given user when he or she is created. Can this be done? Does it require a processor of some kind?

7

You could consider running a script that fires with the user:created event.

Try the following:

Step 1

Create a patch which tells SPE to run scripts for the Sitecore event.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:security="http://www.sitecore.net/xmlconfig/security/">
  <sitecore role:require="Standalone or ContentManagement" security:require="Sitecore">
    <events>
      <event name="user:created">
        <handler type="Cognifide.PowerShell.Integrations.Tasks.ScriptedItemEventHandler, Cognifide.PowerShell" method="OnEvent" />
      </event>
    </events>
  </sitecore>
</configuration>

Step 2

Create a new script containing your profile code. Optionally, add rules on the script to avoid unnecessary script executions (i.e. check for user role).

Script Library

Make sure that the script is nested under a folder structure like [MODULE]/Event Handlers/User/Created/[SCRIPT_NAME]. If you created a new module, be sure that it is marked enabled (doing so changes the icon).

$createdUser = $eventArgs.Parameters[0]
Write-Log "Created new user $($createdUser.Username)"

Update

In my experience, only the ID of an item based on the Large Button template will work.

  • Sorry, I seem to be missing something. Where are you creating this "OnEvent" method? Is this in a separate handler class I need to create in my project? – Levi Wallach Jul 15 at 20:00
  • This is included with SPE. – Michael West Jul 15 at 20:39
  • Can you please join the slack channel to discuss further? – Michael West Jul 17 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.