#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Create Work Area From Template With Specified Level of Sub-Folders

Users have been requesting methods to create new Work Areas in ProjectWise from a Template. However, they don’t always want to copy all of the available sub-folders into the new Work Area. In the past, we have come up with various ways to accomplish this. Fortunately, with the Version 1.20.6.0 release of the PWPS_DAB module, we now have the ability to create a ProjectWise Work Area from a template with only the sub-folders desired using a few of the PowerShell cmdlets we already have available.

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 1.20.6.0. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.

  • Get-PWFolders
  • New-PWRichProject
  • Copy-PWFolder

FolderDepthToCopy

The FolderDepthToCopy parameter within the New-PWRichProject (New-PWRichProjectFromSpreadsheet and New-PWRichProjectFromDataTable) cmdlet allows you to specify the level of sub-folders to be copied into a new Work Area when it is created from a Work Area Template.

-FolderDepthToCopy
Defaults to -1, all folders. 0 will just copy top node, 1 will copy
folders one level down, 2 will copy folders two levels down, etc.

Get Template Project

We will get the ProjectWise Work Area Template folder object to be used later in the script. Also, we will get the Work Area property names from the Project Properties. This will allow us to update the Work Area Property values when creating the new Work Area.

<# Get the Work Area Template folder object. 
    Use the -Slow switch parameter to grab the ProjectProperties. #>
$pwTemplateFolder = Get-PWFolders -FolderID 2839 -JustOne -Slow
# Get a list of the Work Area property names from the template project.
$pwWorkAreaPropertyNames = ( $pwTemplateFolder |
Select-Object ProjectProperties).ProjectProperties.GetEnumerator() |
Select-Object Key
Building Template to be Used
Building Template w/Sub-Folders

Populate Work Area Properties

Now that we have the Work Area Property names, we can add them to a hashtable with the appropriate values. This will be used to update the Work Area Properties for the new Work Area.

$WorkAreaProperties = @{
    PROJECT_Architect             = 'HomeTown Architects'
    PROJECT_Budget                = '250000'
    PROJECT_Country               = 'USA'
    PROJECT_End_Date              = '2022-10-02 00:00:00'
    PROJECT_General_Contractor    = 'Acme Contractors'
    PROJECT_LEED_Certification    = 'Gold'
    PROJECT_Mechanical_Contractor = 'Brian Flaherty'
    PROJECT_Owner                 = 'NWF Investors'
    PROJECT_Percent_Complete      = '0'
    PROJECT_PM_Phone_Number       = '518-867-5309'
    PROJECT_Project_Cleanup       = 'No'
    PROJECT_Project_Description   = 'New Building'
    PROJECT_Project_Location      = 'Navarre, FL'
    PROJECT_Project_Manager       = 'TBD'
    PROJECT_Project_Name          = 'My New Building'
    PROJECT_Project_Number        = '121212'
    PROJECT_Project_Status        = 'Design'
    PROJECT_Scope                 = 'New Construction'
    PROJECT_Size                  = '100000'
    PROJECT_Start_Date            = '2020-05-01 00:00:00'
}

Specify Common Parameter Values

We will be using a Splat to specify a list of parameters and values that will be used in each of the three scenarios to follow.

# Using splat for readability.
$Splat_NewWorkArea = @{
    TemplateName = 'Building Template'
    StorageArea = 'Storage01'
    ProjectProperties = $WorkAreaProperties
    DoNotCopyDocuments = $true
}

Scenario 1 – Create New Work Area – Full Template

In this scenario, we will be creating a new Work Area from the Work Area Template. All content (except the documents) will be included.

Note: We excluded the -FolderDepthToCopy parameter.

# Scenario 1
$Splat_NewWorkArea.NewFolderPath = 'Projects\MyNewBuilding01'
<# Do Not include the FolderDepthToCopy parameter.
    $Splat_NewWorkArea.FolderDepthToCopy = 0
    All template folders will be copied. #>
$pwWorkArea01 = New-PWRichProject @Splat_NewWorkArea
New Work Area Created with All Sub-Folders

Scenario 2 – Create New Work Area – Only Work Area Folder

In this scenario, ONLY the Work Area folder will be included. NO sub-folders will be created.

Note: The -FolderDepthToCopy parameter is set to 0.

# Scenario 2
$Splat_NewWorkArea.NewFolderPath = 'Projects\MyNewBuilding02'
$Splat_NewWorkArea.FolderDepthToCopy = 0
<# By specifying Zero for the FolderDepthToCopy, only the WorkArea folder
will be created. NO sub-folders will be copied. #> $pwWorkArea02 = New-PWRichProject @Splat_NewWorkArea
Only the Work Area Folder was Created

Scenario 3 – Create New Work Area – Work Area Folder and First Level Sub-Folders

In this scenario, we will include the first level of sub-folders from the template Work Area into the new Work Area.

Note: The -FolderDepthToCopy parameter is set to 1.

# Scenario 3
$Splat_NewWorkArea.NewFolderPath = 'Projects\MyNewBuilding03'
$Splat_NewWorkArea.FolderDepthToCopy = 1
<# By specifying Zero for the FolderDepthToCopy, the WorkArea folder will
be created and ONLY the first level of sub-folders will be copied. #> $pwWorkArea03 = New-PWRichProject @Splat_NewWorkArea
First Level Sub-Folders were Created

Copy Sub-Folders From Template to Work Area

We will now copy sub-folders from the template Work Area to the new Work Area created in scenario two. We have a string array which contains two of the available sub-folders from the template. Both of these will be added to the new Work Area with their sub-folders.

# Copy sub-folders to new WorkArea
$SubFoldersToCopy = '02-Shared', '05-Incoming'
foreach ($subFolder in $SubFoldersToCopy) {
    $Splat_CopyFolder = @{
        FolderPath = $pwWorkArea02.FullPath
        FolderToCopy = "$($pwTemplateFolder.FullPath)\$subFolder"
        IncludeSubFolders = $true
        DontCopyWorkflow = $true
    }
    $results = Copy-PWFolder @Splat_CopyFolder
}
Copied Two Sub-Folders and Their Sub-Folders

Summary

We created three new Work Areas from a template. We were able to specify the level of sub-folders to include.  We also, updated the Work Area properties for each of the new Work Areas. Finally, we copied two of the template sub-folders into one of the new Work Areas.


Experiment with it and have fun.

Here is a link to the script file used. 

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 )

Google photo

You are commenting using your Google 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.