Did you know that there is a SQL function provided with ProjectWise which will return all folders within a provided ProjectWise folder specified by the corresponding folder id. The name of the function is dsqlGetSubFolders. In this post, I will show an easy way to retrieve all ProjectWise Folder objects for a provided Work Area / Rich Project.
We will be using the following cmdlets to accomplish this task. All of the ProjectWise related cmdlets are available using the PWPS_DAB module. At the time of this post, I am using version 22.214.171.124. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.
For the dsqlGetSubFolders function, you have three argument values you can provide.
- The first argument value can be either 0 or 1.
- 0 – Do Not include the parent folder when a folder id is provided in the second argument.
- 1 – Include the parent folder when a folder id is provided in the second argument.
- The second argument allows you to provide a folder id for the parent folder to return all subfolders for.
- This value indicates the level. This will be set to 0 (zero).
I will specify 1 for the first argument value and 177 for the second argument value. This is the folder id of the BSI900 – Adelaide Tower Work Area provided with the ProjectWise examples datasource.
In the following
# Folder ID of the Work Area / Rich Project / Folder to obtain all ProjectWise Folder objects for. $ProjectID = 177 [int] $IncludeParentFolder = 1 $SQL = "SELECT o_projguid AS GUID FROM dms_proj WHERE o_projectno IN ( SELECT o_projectno FROM dsqlGetSubFolders ($IncludeParentFolder, $ProjectID, 0) )" # Returns the folder GUIDs for each folder within the provided Work Area folder id. $results = Select-PWSQL -SQLSelectStatement $SQL # Pass the GUIDs to get the ProjectWise Folder objects. $pwFolders = Get-PWFoldersByGUIDs -FolderGUIDs $results.GUID
Experiment with it and have fun.
Hopefully, you find this useful. Please let me know if you have any questions or comments. If you like this post, please click the Like button at the bottom of the page.