Monday, March 26, 2012

ProjectServer 2010: Create Custom Fields and Lookup Tables from PowerShell

In this post we’ll demonstrate how to create Lookup Table and Custom Fields on PWA from PowerShell.
All you need is create several objects with types from FluentPS.Model namespace and use LookupTableService or CustomFieldService to create items on ProjectServer instance.

See the full source:
$fluentps = Get-FluentPS -PWAUrl "http://localhost/PWA"

$lookup = new-object FluentPS.Model.PSLookupTableInfo
$lookup.Name = "LT Test1"
$lookup.Type = [FluentPS.Enums.PSFieldType]::Text

$lookupsToCreate = New-Object 'System.Collections.Generic.List[FluentPS.Model.PSLookupTableInfo]'


$cf = new-object FluentPS.Model.PSCustomFieldInfo
$cf.FieldName = "Test Field 1"

$lcf = new-object FluentPS.Model.PSLookupFieldInfo
$lcf.FieldName = "Test Lookup Field 1"
$lcf.LookupTableName = "LT Test1"

$fieldsToCreate = New-Object 'System.Collections.Generic.List[FluentPS.Model.PSCustomFieldInfo]'

$fluentps.CustomFieldService.SaveOrUpdateCustomFields($fieldsToCreate, [FluentPS.Enums.PSEntityType]::Project)

Have fun!