none
PS2010 How to remove windows account from user through PSI

    Pertanyaan

  • Hi there

    We have a client that still uses PS2010 and has asked us to create a functionality to add and remove Network windows account from a user. For creating a user is quite straight forward, but for some reason we have not succeed in removing the windows account. We also have managed to deactivate, but we also need to remove the windows account and we have not figure out how to do that. 

    Any help is welcome.

    The codes are the following:

    //for creating the nt windows account user the code is the following - it is working fine
     using (WSResource.Resource ResourceWS = new WSResource.Resource())
                    {
                        NetworkCredential nc = new NetworkCredential(Helpers.Global.CredentialUser, Helpers.Global.CredentialPassword, Helpers.Global.CredentialDomain);

                        ResourceWS.Url = Helpers.Global.UrlPwaSite + "/_vti_bin/PSI/Resource.asmx";
                        ResourceWS.Credentials = nc;

                        ResourceDataSet resDs = new WSResource.ResourceDataSet();
                        WSResource.ResourceDataSet.ResourcesRow resourceRow = resDs.Resources.NewResourcesRow();

                        resourceRow.RES_UID = resourceUID;
                        resourceRow.RES_NAME = resourceName;
                        resourceRow.RES_INITIALS = resourceName.Substring(0, 1) + (resourceName.IndexOf(" ") > 0 ? resourceName.Substring(resourceName.IndexOf(" ") + 1, 1) : "");
                        resourceRow.RES_TYPE = (int)PSLibrary.Resource.Type.WorkResource;
                        resourceRow.WRES_EMAIL = resourceEmail;
                        resDs.Resources.AddResourcesRow(resourceRow);  
                        ResourceWS.CreateResources(resDs, false, true);
                        if (!string.IsNullOrEmpty(resourceNTAccount))
                        {
                            WSResource.ResourceAuthorizationDataSet resourceAuthDs = new WSResource.ResourceAuthorizationDataSet();
                            WSResource.ResourceAuthorizationDataSet.ResourcesRow resourceAuthRow = resourceAuthDs.Resources.NewResourcesRow();
                            resourceAuthRow.RES_UID = resourceUID;
                            resourceAuthRow.RES_IS_WINDOWS_USER = true;
                            resourceAuthRow.WRES_ACCOUNT = Helpers.Global.CredentialDomain + "\\" + resourceNTAccount;
                            resourceAuthDs.Resources.AddResourcesRow(resourceAuthRow);
                            ResourceWS.SetResourceAuthorization(resourceAuthDs);
                        }

                        Guid gpUID = new Guid("");
      WSSecurity.Security objSecurity = new WSSecurity.Security();
                        objSecurity.Credentials = nc;
                        WSSecurity.SecurityGroupsDataSet secutiryAuthDs = new WSSecurity.SecurityGroupsDataSet();
                        secutiryAuthDs = objSecurity.ReadGroup(gpUID);
                        WSSecurity.SecurityGroupsDataSet.GroupMembersRow securityAuthRow = secutiryAuthDs.GroupMembers.NewGroupMembersRow();
                        secutiryAuthDs.GroupMembers.AddGroupMembersRow(gpUID, resourceRow.RES_UID);
                        objSecurity.SetGroups(secutiryAuthDs);
                    }

    //for removing windows account - IT IS NOT WORKING
    using (WSResource.Resource ResourceWS = new WSResource.Resource())
                    {
                        NetworkCredential nc = new NetworkCredential("user", "pass", Helpers.Global.CredentialDomain);
                        ResourceWS.Url = Helpers.Global.UrlPwaSite + "/_vti_bin/PSI/Resource.asmx";
                        ResourceWS.Credentials = nc;
                        WSResource.ResourceAuthorizationDataSet resourceAuthDs = ResourceWS.ReadResourceAuthorization(resourceUID);
                        WSResource.ResourceAuthorizationDataSet.ResourcesRow resourceAuthRow = resourceAuthDs.Resources[0];
                        resourceAuthRow.RES_UID = resourceUID;
                        resourceAuthRow.RES_IS_WINDOWS_USER = false;
                        resourceAuthRow.SetWRES_ACCOUNTNull();
                        ResourceWS.SetResourceAuthorization(resourceAuthDs);
                    }

     ResourceWS.SetResourceAuthorization(resourceAuthDs):
    {"ProjectServerError(s) LastError=GeneralUnhandledException "} 



    Thanks.



    PL

    Jumat, 08 Juni 2018 18.00

Semua Balasan

  • You cannot remove the windows account.  It was possible at one time to put invalid or fake accounts in resource profile, however, a project server patch, later prevented this.  If you 2010 is not up-to-date, then you may be able to use fake accounts.   Fake accounts are windows accounts that are not actually found in AD.  The patch fix this by validating accounts before allowing it to be saved.

    Another possibility is to use form based account, however, that opens up another can of worms.


    Michael Wharton, Project MVP, MBA, PMP and a Great Guy <br/> Website http://www.WhartonComputer.com <br/> Blog http://MyProjectExpert.com contains my field notes and SQL queries

    Minggu, 10 Juni 2018 04.36
    Moderator
  • Hi Michael

    thanks for your reply. However, I think that is not what I meant. Sorry if I was not clear enough.

    Let me try to be more specific.

    This client of mine has a huge employee turnover, so what he really needs is to unset the flag that states that a user can logon and deactivated this user. I have managed to deactivate the user, but I do not know how to unset the flag "Resource can logon to project server". 

    I thought that I just had to set false for "resourceAuthRow.RES_IS_WINDOWS_USER = false". But it did not work.

    I am attaching a image showing exactly what I meant, hope so. :)

    I appreciate any help.

    Thanks.


    PL

    Senin, 11 Juni 2018 19.09