Creating a Project Server User and Adding User to a group through PSI
Introduction
Below PSI sample code is to Create a user in Project server and Add the user to a specific Group
Sample Code
public static Guid CreatePsvrUser(string resname, string ntAcc)
{
Guid gpUID = new Guid("303D8BA6-BD1A-437A-984E-B19AD11EF345"); //group UID can be found from MSP_WEB_SECURITY_GROUPS
ResourceWS.Resource resourceClient = new ResourceWS.Resource();
resourceClient.Credentials = nc;
ResourceWS.ResourceDataSet resDs = new ResourceWS.ResourceDataSet();
srvSecurity.Security objSecurity = new srvSecurity.Security();
objSecurity.Credentials = nc;
ResourceWS.ResourceDataSet.ResourcesRow resourceRow = resDs.Resources.NewResourcesRow();
Guid NewResGuid = Guid.NewGuid();
resourceRow.RES_UID = NewResGuid;
resourceRow.RES_NAME = resname;
resourceRow.RES_TYPE = (int)PSLibrary.Resource.Type.WorkResource;
resDs.Resources.AddResourcesRow(resourceRow);
resourceClient.CreateResources(resDs, false, true);
ResourceWS.ResourceDataSet.ResourceAvailabilitiesRow resAvailRow = resDs.ResourceAvailabilities.NewResourceAvailabilitiesRow();
resAvailRow.RES_UID = resourceRow.RES_UID;
resAvailRow.SetRES_AVAIL_FROMNull();
resAvailRow.SetRES_AVAIL_TONull();
resAvailRow.RES_AVAIL_UNITS = 100;
resDs.ResourceAvailabilities.AddResourceAvailabilitiesRow(resAvailRow);
ResourceWS.ResourceAuthorizationDataSet resourceAuthDs = new ResourceWS.ResourceAuthorizationDataSet();
ResourceWS.ResourceAuthorizationDataSet.ResourcesRow resourceAuthRow = resourceAuthDs.Resources.NewResourcesRow();
resourceAuthRow.RES_UID = resourceRow.RES_UID;
resourceAuthRow.RES_IS_WINDOWS_USER = true;
resourceAuthRow.WRES_ACCOUNT = ntAcc;
resourceAuthDs.Resources.AddResourcesRow(resourceAuthRow);
resourceClient.SetResourceAuthorization(resourceAuthDs);
srvSecurity.SecurityGroupsDataSet secutiryAuthDs = new srvSecurity.SecurityGroupsDataSet();
secutiryAuthDs = objSecurity.ReadGroup(gpUID);
srvSecurity.SecurityGroupsDataSet.GroupMembersRow securityAuthRow = secutiryAuthDs.GroupMembers.NewGroupMembersRow();
secutiryAuthDs.GroupMembers.AddGroupMembersRow(gpUID, resourceRow.RES_UID);
objSecurity.SetGroups(secutiryAuthDs);
return NewResGuid;
}
Happy coding ......Cheers .. Ajith