none
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
    $projContext.Load($projects)
    $projContext.ExecuteQuery()
    
    $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
            $projContext.ExecuteQuery()
        }
    }
    

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

    What is wrong here?

    Regard


    Tanzim Akhtar

    Sunday, March 24, 2019 1:55 PM

Answers

All replies

  • Hello,

    How come you have:

    $project.Name =

    and not:

    $draftProject.Name =

    ?

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Sunday, March 24, 2019 9:04 PM
    Moderator
  • 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


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Monday, March 25, 2019 11:36 PM
    Moderator
  • 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

    Regards


    Tanzim Akhtar

    Tuesday, March 26, 2019 6:53 AM