#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Fastest Way to Get FolderPath

Be sure to check out my Scripting4Crypto initiative. It’s a fun way to get into using cryptocurrencies all while getting your PowerShell needs met.


I am updating my post. Thanks to Dave Brumbaugh for pointing out a functionality with the Get-PWFolders that I overlooked. Since Version of the PWPS_DAB module, the Get-PWFolders has had the -PopulatePaths switch parameter available. This switch parameter offers a way to populate the paths to the folders without the overhead of using the -Slow switch parameter. This appears to be the quickest way to retrieve the full path for folders.

Therefore, I have added a fourth scenario to this post.

I have been doing a lot of testing lately regarding the quickest (hopefully most efficient) ways to obtain various ProjectWise data. In this post, I will be focusing on getting the FullPath for ProjectWise folder objects. This is one of the slower processes.

To obtain the FullPath of a folder object, you typically need to include the -Slow switch parameter when using the Get-PWFolders cmdlet. I say typically, because if you return only one folder object by including the -JustOne switch parameter, the FullPath is included.

Just to demonstrate my point, the following code snippet will not return the folders FullPath with the Folder Object.

Get-PWFolders -FolderPath 'PowerShell\MoveFrom'
Folder Object – No FullPath

However, the following will.

Get-PWFolders -FolderPath 'PowerShell\MoveFrom' -JustOne
Folder Object – FullPath Included

 Now, lets take a look at a few ways to get a folders FullPath. For each of the following scenarios, we will be using the Get-PWFolders cmdlet with various options, wrapped with the Measure-Command cmdlet to capture the time it takes to complete the process.

NOTE: There are 412 folders returned for each of the scenarios.

Scenario One

The first scenario is probably the most common. With the Get-PWFolders cmdlet, we will include the -Slow switch parameter. The -Slow parameter tells the cmdlet to include general attribute data pertaining to the folder, including the folder path.

# Scenario One
Measure-Command {
    $PWFOlderNames = Get-PWFolders -Slow | Select-Object FullPath
Scenario One Results

You can see that it took 5.6043219 seconds to complete the process in Scenario One.

Scenario Two

In the second scenario we will again be using the Get-PWFolders cmdlet to get all ProjectWise folders and pipe the results to the Get-PWFolderPathAndProperties cmdlet.

# Scenario Two
Measure-Command {
    $PWFOlderNames = Get-PWFolders | 
    Get-PWFolderPathAndProperties | Select-Object FullPath
Scenario Two Results

You can see that it took 2.7905419 seconds to complete the process in Scenario Two.

Scenario Three

In the third scenario we will be using a new technique to populate the full path. We will be using the Foreach method available when the return object is a collection type. In this case it is an Object array.

The following will demonstrate how to determine the type of object returned from the Get-PWFolders cmdlet. The second code snippet will return the object type for an individual array item. We should end up with an array of ProjectWise Folder objects.

(Get-PWFolders -FolderID 177).GetType().FullName

(Get-PWFolders -FolderID 177)[0].GetType().FullName 
Object Types Returned

# Scenario Three
Measure-Command {
    $PWFOlderNames = (Get-PWFolders).foreach({
        Get-PWFolderPathAndProperties -InputFolder $_
    }) | Select-Object FullPath
Scenario Three Results

You can see that it took 3.3105754 seconds to complete the process in Scenario Three.

Scenario Four

Finally, in scenario four, we will be using the -PopulatePaths switch parameter with the Get-PWFolders cmdlet. This was added in Version of the PWPS_DAB module.

# Scenario Four
Measure-Command {
    $PWFOlderNames = Get-PWFolders -PopulatePaths | Select-Object FullPath
Scenario Four Results

You can see if took 0.2933399 seconds. This is significantly faster than the other 3 approaches. (Thanks again Dave.)


The ProjectWise datasource I used is on a personal development VM and doesn’t contain much data. Therefore the resulting times it took to complete each process is very small. However, I have tested this against larger datasources and the results are consistent.

Scenario Four seems to contain the quickest method of obtaining the full path of multiple ProjectWise folder objects.

Get-PWFolders -PopulatePaths

Please do similar tests and let me know if you find any contrary results. 

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.