none
How should I deactivate project server user account using C# or powershell RRS feed

  • Question

  • Hi,

    I have thousands of user account in my PWA site which need to be deactivated. I have those user account in excel.

    How should I deactivate those account using power shell or by using C# CSOM?

    Thanks in advance.

    Hazeq.

    Friday, December 13, 2013 6:39 PM

Answers

  • $projContext = New-Object Microsoft.ProjectServer.Client.ProjectContext($PWAInstanceURL) 
    [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($PWAUserName, $securePass);  
    $projContext.Credentials = $spocreds 


    $projContext.Load($projContext.EnterpriseResources);
    $projContext.ExecuteQuery()  
    $erp = $projContext.EnterpriseResources;

    foreach($ers in $erp) {
            if($ers.Name -eq "name_here") #Update the resource name which needs to be deactivated
    {
    $ers.IsActive =0
    }
    }
    $erp.Update();
    $projContext.ExecuteQuery()  

    tatiana

    Tuesday, April 17, 2018 8:26 PM

All replies

  • Hi Hazeq,

    We dont have any specific Cmdlets (Powershell) command for deactivate Project server 2013 users.

    http://technet.microsoft.com/en-us/library/ee890097.aspx

    Only way to Deactivate user is from Manage users under server setting. You can select Multiple users at a time then you can deactivate them in a single shot.

    http://technet.microsoft.com/en-us/library/cc197243.aspx

    Or

    If you are using AD synchronization for your Project Serve group then if User accounts are not present on AD then sync will deactivate all the account. 

    Or

    You could use PSI to deactivate the project server users accounts.

    Below mentioned method is for modify or deactivate the user account from Project server.

     

    Class Resource Update or delete existing resources or Project Server users. Also allows creation of new resources or users.
    To deactivate a resource, add 100 to its RES_TYPE value. The resource type RES_TYPE is 1 to 99 for active resources and 101 to 199 for inactive resources.

    void UpdateResources(
      ResourceDataSet rds,
      bool validateOnly,
      bool autoCheckIn
    );

    http://msdn.microsoft.com/en-us/library/office/gg208103.aspx

    Link Will guide you with code sample.

     


    kirtesh


    • Proposed as answer by Kirteshtiw Sunday, December 15, 2013 12:50 PM
    • Edited by Kirteshtiw Sunday, December 15, 2013 1:14 PM
    Sunday, December 15, 2013 12:50 PM
  • $projContext = New-Object Microsoft.ProjectServer.Client.ProjectContext($PWAInstanceURL) 
    [Microsoft.SharePoint.Client.SharePointOnlineCredentials]$spocreds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($PWAUserName, $securePass);  
    $projContext.Credentials = $spocreds 


    $projContext.Load($projContext.EnterpriseResources);
    $projContext.ExecuteQuery()  
    $erp = $projContext.EnterpriseResources;

    foreach($ers in $erp) {
            if($ers.Name -eq "name_here") #Update the resource name which needs to be deactivated
    {
    $ers.IsActive =0
    }
    }
    $erp.Update();
    $projContext.ExecuteQuery()  

    tatiana

    Tuesday, April 17, 2018 8:26 PM
  • Hello Tatiana,  that's a very clear way and will mark it as answered. 

    However, another way to do this is to sync the AD group team members and if they are deactivated in AD, they will be deactivated in Project server.


    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

    Tuesday, April 17, 2018 8:56 PM
    Moderator