Following on from my previous mini series of posts for including the HTML formatting in Project Online Power BI reports, this post is a supporting blog post for the PowerShell script I used in the 3rd post. For those that missed that mini series of posts, the links are below:
This blog post is the supporting blog post for the script sample published to the Microsoft Script Gallery: https://gallery.technet.microsoft.com/Online-Level-HTML-fields-5dc31a38
This PowerShell script will use the Project Reporting OData API to get all of the published projects in the Project Online PWA Site Collection, then for each project it will get the project level multiple lines of text fields that include the HTML from the REST API and then create a list item on the specified SharePoint list. The user setting up the script will need to make some changes to the script , this is covered in the blog post.
The account used will need access to the OData API in PWA, at least full read access to all projects and contribute access to the target SharePoint list. The SharePoint list will also need to be created beforehand with the required columns.
To get the script to work you will need to reference the DLL as seen in the image below:
This can be installed from the SharePoint Online Client components / management shell. I used the dll from the SharePoint Online Management Shell in this example.
Firstly decide what project level multiple lines of text fields you want to include, this will determine the list column requirements. Then create the SharePoint list in the PWA site collection with the required columns, for this example I created a list called ProjectMutliLineFields with the columns below:
I used the default Title field for the Project Name, ProjectId for the Project GUID then I created four multiple lines of text columns for my example project multiple lines of text fields. Set up the list and columns as required then update line 45 in the sample script to change the select query to include the correct project fields you need:
$url = $PWAInstanceURL + "/_api/ProjectServer/Projects(guid'$projectID')/IncludeCustomFields?`$Select=Name,Id,Custom_x005f_4d0daaaba6ade21193f900155d153dd4,Custom_x005f_3f9c814ca2ade21193f900155d153dd4,Custom_x005f_a801708ea5ade21193f900155d153dd4,Custom_x005f_70534c6aa2ade21193f900155d153dd4"
You will at least need to change all of the custom field GUIDs to be the correct GUIDs for your project fields. If you are unsure on how to get the correct custom field GUIDs, see post 2 in the HTML reporting series.
You will then need to update the list item creation part of the sample script to map to the correct SharePoint column names you created and the project fields:
Also ensure the variables have been updated correctly, placeholder values seen below:
Save and run the PowerShell script (fully test on a non-production PWA site collection before Production) to ensure the data is captured correctly in the target SharePoint list. This script could be run manually on demand or on schedule using a scheduled task if running on a server or a scheduled Azure Function or other methods.
Once the script is run you will see the data in the SharePoint list (data from our sales demo instance):
Whilst the purpose of this script was to enable us to get the data easily in Power BI in a such a way that supported refreshing in the Power BI Service, as you can see in the screen shot above, this list includes all of the HTML formatting in a central view – something you can’t get in a PWA Project Center view! Do keep in mind that this SharePoint list would not be security trimmed like a Project Center view though, so you might want to restrict access to the SharePoint list depending on your data / security policies for your PPM data.
Running the script multiple times will create multiple items for each project so you might want to set up grouping on the view or update the script to modify the SharePoint list item with the updated data so that you only have one list item per project.
The script is provided "As is" with no warranties etc.