Working with Project Server many a times we come across a requirement of creating numerous custom fields and lookup tables which is a time-consuming job. To, overcome this I will be sharing with you how to create an automated script using PowerShell script.
I have used Project server PSI services which will be complied in the script itself to generate an assembly to carry out the operation. Â The same operation can be accomplished with CSOM also but due to limitation of not creating Graphical Indicator fields used PSI services.
The complete PowerShell script is attached and comprises of 3 files. Below are the details:
File |
Content |
Deploy-Config.PS1 |
Contains details of Project Server instance to be used. |
DeployFields-PWA.PS1 |
Complete Power shell script file. |
ProjectServerFields.XML |
Contains details of custom fields and lookup tables that needs to be created. |
To run the PowerShell script user must have admin rights and permission to run PSI services.
Using DeployFields-PWA.PS1 script, you will be able to create single level lookup tables and custom fields for any entity type (project, task, resource).
A log file is also created under the folder where the script file resides which shows the detail of the lookup table and custom fields being created.
Let’s discuss the various steps needed for deployment.
- Load Microsoft.Office.Project.Server.Library in the file by writing below command at the top of the script file[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Project.Server.Library”)
- Load the Deploy -Config.PS1file to read Project Server Instance details in the script.
- Test-IsAdmin method is used to check user running the script has administrative rights or not. If Yes, then will move further else exit.
- Creating an assembly from the PSI WSDL service at run time Here, we will be generating the precompiled assembly for the custom field and lookup table PSI services. For this GetPSIServiceAssembly param([string] $webServiceUrl, [string[]] $referenceAssemblies)Â method is created and parameters being passed are: PSI WSDL URL and the Assemblies references required to compile the WSDL. The assembly references are: “System.dll”, “System.Web.Services.dll”, “System.Xml.dll”, “System.Data.dll”.
- Creation of Enterprise Project server fields. The WSDL assembly created in above step will be used to create the project server enterprise fields. A single PowerShell method LookupTable_CustomFieldsCreation is created in which we will first create the lookup tables and then the custom fields.The lookup table PSI service url is:
+ “/_vti_bin/psi/LookupTable.asmx?wsdl”
The custom fields PSI service url is:
+ “/_vti_bin/psi/CustomFields.asmx?wsdl”
- Creating lookup tables
- Read each entry of lookup tables from ProjectServerFields.xml file. If lookup table with same name exist in project server, then continue with the next.
- If the lookup table doesn’t exist, then create a new lookup table row.Â
- Creating custom fields
- Get the entity id of the various entity type i.e. project, task and resource
- Get the list of existing custom fields associated with each of the entity type.
- Get the Lookup table id if custom field is associated to lookup table.
- If custom field do not exist create a new custom field row.Â
- Creating lookup tables
- To run the script, give the path of DeployFields-PWA.PS1 file on Windows Power Shell Console.
This is how lookup tables and custom fields are created using power shell scripting. In my next blog I will be explaining how the Graphical Indicators are created using the power shell script.
You can get the complete PowerShell script package from here.