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

%3CLINGO-SUB%20id%3D%22lingo-sub-1842610%22%20slang%3D%22en-US%22%3EUpdate%20Project%20Department%20Custom%20Field%20in%20project%20Server%202016%20-%20via%20CSOM%2FPowershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1842610%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20wanted%20to%20update%20%3CU%3EProject%20Department%3C%2FU%3E%26nbsp%3B%20Custom%20Field%20in%20Project%20Server%202016%20via%20CSOM%20%2F%20PowerShell%20script.%3C%2FP%3E%3CP%3EI%20tried%20below%20Script%20%3A%20but%20no%20luck..%3C%2FP%3E%3CP%3EAny%20Pointers%20please%20...%3C%2FP%3E%3CPRE%3E%26nbsp%3B%3CSPAN%20class%3D%22powerShell__keyword%22%3Etry%3C%2FSPAN%3E%26nbsp%3B%7B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24projectName%3C%2FSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.ProjectName%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CFONT%20color%3D%22%23FF0000%22%3E%5BArray%5D%3CSPAN%20class%3D%22powerShell__variable%22%3E%24MyArray1%3C%2FSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.Dept%3C%2FFONT%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%5BArray%5D%3CSPAN%20class%3D%22powerShell__variable%22%3E%24MyArray3%3C%2FSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.multiselect1%2C%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.multiselect2%2C%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.multiselect3%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24project%3C%2FSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24projContext%3C%2FSPAN%3E.Projects%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E%7C%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22powerShell__alias%22%3Eselect%3C%2FSPAN%3E%26nbsp%3BId%2C%26nbsp%3BName%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E%7C%3C%2FSPAN%3E%26nbsp%3Bwhere%26nbsp%3B%7B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.Name%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E-%3C%2FSPAN%3Eeq%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24projectName%3C%2FSPAN%3E%7D%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__keyword%22%3Eif%3C%2FSPAN%3E(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24project%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E-%3C%2FSPAN%3Ene%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24null%3C%2FSPAN%3E)%7B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24proj%3C%2FSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24projContext%3C%2FSPAN%3E.Projects.GetByGuid(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24project%3C%2FSPAN%3E.Id)%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24draftProject%3C%2FSPAN%3E%26nbsp%3B%3D%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24proj%3C%2FSPAN%3E.CheckOut()%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24draftProject%3C%2FSPAN%3E.SetCustomFieldValue(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24Dept%3C%2FSPAN%3E%2C%3CFONT%20color%3D%22%23FF0000%22%3E%3CSPAN%20class%3D%22powerShell__variable%22%3E%24MyArray1%3C%2FSPAN%3E%3C%2FFONT%3E)%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24draftProject%3C%2FSPAN%3E.SetCustomFieldValue(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24Cost%3C%2FSPAN%3E%2C%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.Cost)%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24draftProject%3C%2FSPAN%3E.SetCustomFieldValue(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24multiselect%3C%2FSPAN%3E%2C%3CSPAN%20class%3D%22powerShell__variable%22%3E%24MyArray3%3C%2FSPAN%3E)%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24draftProject%3C%2FSPAN%3E.SetCustomFieldValue(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24State%3C%2FSPAN%3E%2C%3CSPAN%20class%3D%22powerShell__variable%22%3E%24_%3C%2FSPAN%3E.State)%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24draftProject%3C%2FSPAN%3E.Publish(%3CSPAN%20class%3D%22powerShell__variable%22%3E%24true%3C%2FSPAN%3E)%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E%7C%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22powerShell__cmdlets%22%3EOut-Null%3C%2FSPAN%3E%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__variable%22%3E%24projContext%3C%2FSPAN%3E.ExecuteQuery()%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BWrite%3CSPAN%20class%3D%22powerShell__operator%22%3E-%3C%2FSPAN%3Ehost%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E-%3C%2FSPAN%3EForegroundColor%26nbsp%3BGreen%26nbsp%3B%3CSPAN%20class%3D%22powerShell__string%22%3E%22'%24projectName'%26nbsp%3Bhas%26nbsp%3Bbeen%26nbsp%3Bupdated%22%3C%2FSPAN%3E%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7D%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%20class%3D%22powerShell__keyword%22%3Eelse%3C%2FSPAN%3E%26nbsp%3B%7B%26nbsp%3B%0A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BWrite%3CSPAN%20class%3D%22powerShell__operator%22%3E-%3C%2FSPAN%3Ehost%26nbsp%3B%3CSPAN%20class%3D%22powerShell__operator%22%3E-%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgallery.technet.microsoft.com%2Fprojectserver%2FUpdate-Server-Custom-Field-00ab99a9%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgallery.technet.microsoft.com%2Fprojectserver%2FUpdate-Server-Custom-Field-00ab99a9%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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