Update #ProjectOnline Resource custom field values using #PowerShell with data from #AzureAD user attributes #PPM #Offce365 #ProjectServer #CSOMNovember 7, 2016 at 9:40 pm | Posted in Add-on, Administration, Configuration, Customisation, Functionality, Information, PowerShell, Reporting | Leave a comment
Tags: Office365, PowerShell, PPM, Project 2013, Project 2016, Project Online, Project Server 2013, Project Server 2016, SharePoint Online
This blog post will demonstrate a simple example of how Microsoft’s PPM tool, Project Online, can include / sync metadata from Azure AD user attributes to resource custom fields in Project Online. This example script will update the resource custom field “Job Title” on my test tenant with the data from the Azure AD user “Title” attribute.
This script example can be downloaded here: https://gallery.technet.microsoft.com/Update-Online-Resource-83137b7f
The script does require some additional modules / DLLs to work. Firstly you will need the Azure AD module installed, this can be downloaded here: http://connect.microsoft.com/site1164/Downloads/DownloadDetails.aspx?DownloadID=59185. You will also need the SharePoint Online and Project Online CSOM DLLs. The DLL’s used are from the NuGet package here: https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/16.1.5521.1200. There are later version available, check here: https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM. Download those as required. These modules can be seen here on line 3,5 and 14 in the example script, the location will need to be updated to reference the correct location for your SP / PS Online CSOM DLLs.
The user setting up the script will need to update the correct location to the DLLs required, the AD username, AD password, CSV file location, PWA instance URL, username, password and the custom field internal name. The PWA account specified will need edit access to all of the resources in PWA and the AD account will need access to read all the users in Azure AD. Ensure the variables have been updated correctly, placeholder values seen below:
In this example all users in the Azure AD will be exported, clearly if you have a large organisation it would be efficient the filter for only those users that exist in Project Online. The code matches users and resources based on the AD display name and PWA resource name when updating the resources in PWA.
To get the correct custom field internal ID I use the REST API, <PWA Site URL> + /_api/ProjectServer/CustomFields. Find the resource level custom field and copy the InternalName as seen below:
Once the PowerShell script has been updated, save it and it can then be tested on a test / non-production environment. Once executed in PowerShell, each resource found in the CSV file will be outputted as seen in the example below. In this example there are many AD users in the CSV export that do not exist in the PWA instance.
Checking in the Resource Center after the script has run you can see for the resources that exist in the CSV file created, the Job Title has been updated with the values found in Azure AD / the export CSV file:
The CSV file generated can be seen here:
This PowerShell script could be run on a schedule from a server on-prem or even in Azure / webjob. The script would just need access to save / access a CSV file and the DLLs / modules required. Fully test this script on a test / non-production PWA instance before running on a Production PWA instance.
The script is provided “As is” with no warranties etc.