I am trying to automate few daily tasks for some of Tridion admins. We have 800+ publications 600+ users and more than 1000 groups. So, I am trying to automate user creation. Recently we have migrated from 2009 version, where I used COM+ to achieve this, but that code is not working anymore on 2013. I want to use core service, hence would be great if some sample project is available. I am using C# (4.0 framework).
2 Answers
My blog post on Setting Rights and Permissions has example code in Powershell which includes creating users and adding groups to them. It should be straightforward enough to implement similar logic in C#.
I assume you are talking about user creation that isn't covered already by synchronization with Active Directory and other such features available out-of-the-box.
To create a user using the Core Service is fairly straight-forward. It involves these steps:
- Create a new
SessionAwareCoreServiceClient
. - Call
GetDefaultData
on the client and pass inItemType.User
as the first parameter. This will give you a UserData object with all of the default data filled in. - Set the properties you care about, such as
Title
,Description
,Privileges
, etc. - Save the user by calling
Create
on the client and passing in the user object.
The only sample code I have for this is the Tridion PowerShell Modules project I wrote. Perhaps it is still useful for you? If so, have a look at the New-User function in Trustees.ps1. You could even use these modules to automate it, if you know how to use PowerShell.
Also, be sure to download the Core Service API documentation from the 2013 SP1 documentation.
-
Hi Peter, thanks a lot. I am not very comfortable at using Powershell. I have a website built in the same location where Tridion CMS is hosted. So basically the main URL is same, but I am using a different location to host my website. I have a list of AD accounts who can use it but I also want to impersonate all activities via one account already in CMS as ADMIN. Sep 14, 2015 at 10:29
-
Hi Peter, I saw the powershell implementation and tried to use it in C#. I am having few problems. The major problem is how I can set up the new user to be added to a group and then set the publication scope. The GroupMembershipData object has Group and Scope both. Group is of LinkToGroupData object type, where I can define two main stuff, an Id Ref (TCM ID), a Title. At the moment I am unable set them as the way powershell code is done in C#. Any help would be very much appreciated. Jan 19, 2016 at 13:54
-
I would have to see the code to know what is going wrong. But have a look at the following answer: tridion.stackexchange.com/a/2995/141 If you still cannot get it to work, perhaps you could ask a new question specific to how you add group memberships to users/groups? And include the code you wrote so we can help troubleshoot it. Jan 19, 2016 at 15:49
-
Excellent!! I was looking for this.. Many many many thanks Peter Jan 20, 2016 at 12:52
-