How to update project name using powershell? RRS feed

  • Question

  • Hello,

    We are running Project Server 2016.

    I am running the following script to update all the projects in our PWA:

    $uri = "http://ppm/sites/pwa"
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.ProjectServer.Client.dll" 
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 
    $projContext = New-Object Microsoft.ProjectServer.Client.ProjectContext($uri)
    $projects = $projContext.Projects
    $projects = $projContext.Projects|select Id,Name
    foreach ($project in $projects)
        if ($project -ne $null)
            $proj = $projContext.Projects.GetByGuid($project.Id)
            $draftProject = $proj.CheckOut()
            $project.Name = $project.Name + " abc"
            $draftProject.Publish($true) | Out-Null

    The projects get published, all of them. However it doesn't get updated.

    What is wrong here?


    Tanzim Akhtar

    Sunday, March 24, 2019 1:55 PM


All replies

  • Hello,

    How come you have:

    $project.Name =

    and not:

    $draftProject.Name =



    Paul Mather | Twitter | | CPS | MVP | Downloads

    Sunday, March 24, 2019 9:04 PM
  • Hi,

    Ok so that was the mistake. I will check it and let you know in sha' Allaah.

    Thank you Paul.

    Tanzim Akhtar

    Monday, March 25, 2019 6:36 AM
  • I run the command but face with another error:

    Exception calling "ExecuteQuery" with "0" argument(s): "CSOMUnknownUser"
    At D:\development\Untitled1.ps1:22 char:9
    +         $projContext.ExecuteQuery()
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ServerException

    Moreover I checked this on the internet and found that the project is checked out. However I have seen my PWA and none of the projects are checked out.

    I hope I am writing in correct syntax.

    Tanzim Akhtar

    Monday, March 25, 2019 6:46 AM
  • Add a Try Catch block inside the foreach loop and see if any projects get updated.


    Paul Mather | Twitter | | CPS | MVP | Downloads

    Monday, March 25, 2019 11:36 PM
  • Subhaan Allaah, I got it where the error was.

    It was the opening curly braces. The opening curly braces should be on the same line that of the ForEach-Object loop and putting it on the next line was creating the error. I read this on one of the Microsoft forums.

    Thank you and


    Tanzim Akhtar

    Tuesday, March 26, 2019 6:53 AM