Update Project Department Custom Field in project Server 2016 - via CSOM/Powershell

Copper Contributor

Hi,

I wanted to update Project Department  Custom Field in Project Server 2016 via CSOM / PowerShell script.

I tried below Script : but no luck..

Any Pointers please ...

 try {         
        $projectName = $_.ProjectName 
        [Array]$MyArray1 = $_.Dept   
        [Array]$MyArray3 = $_.multiselect1,$_.multiselect2,$_.multiselect3       
        $project = $projContext.Projects | select Id, Name | where {$_.Name -eq $projectName} 
        if($project -ne $null){ 
            $proj = $projContext.Projects.GetByGuid($project.Id) 
            $draftProject = $proj.CheckOut() 
            $draftProject.SetCustomFieldValue($Dept,$MyArray1)             
            $draftProject.SetCustomFieldValue($Cost,$_.Cost) 
            $draftProject.SetCustomFieldValue($multiselect,$MyArray3)             
            $draftProject.SetCustomFieldValue($State,$_.State) 
            $draftProject.Publish($true| Out-Null 
            $projContext.ExecuteQuery() 
            Write-host -ForegroundColor Green "'$projectName' has been updated" 
            } 
        else { 
            Write-host -

https://gallery.technet.microsoft.com/projectserver/Update-Server-Custom-Field-00ab99a9 

Thanks

 

0 Replies