#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Create a Work Area from a Template

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.

In this post, we will be creating a new ProjectWise (PW) Work Area from a PW Template. This is a pretty straight forward process. I will be including some validation and a little error handling.

All of the ProjectWise related cmdlets are available using the PWPS_DAB module. At the time of this post, I am using version 1.12.8.0. Take a look at the help for each of the cmdlets to become familiar with their functionality, available parameters, etc.

  • Show-PWFolderBrowserDialog
  • Get-PWProjectTemplates
  • New-PWRichProjectFromTemplate

Populate Variables

I have a few variables to be created and populated.

# Name and description of new Work Area to be created.
$NewProjectName = "MyTestProject"
$NewProjectDescription = "My Test Project (Created via PowerShell)"
# Name of template to be used. This will be validated prior to continuing.
$TemplateName = "XXXXXX - Template"
<# Enter the name of the storage area to be used.
Otherwise, use the target folder's storage area. #>
$StorageArea = [string]::Empty

Select Target Folder

First thing we need to do is select the folder to create the new Work Area in. To do this I will be using the Show-PWFolderBrowserDialog cmdlet. You can also use the Get-PWFolders to do the same.

<# Get ProjectWise folder object where 
the new Work Area (Rich Project) will be created. #>
$TargetFolder = Show-PWFolderBrowserDialog

The following shows the Select Folder for PowerShell dialog to select the target folder.

Select Project

Validate Template

Next, we will verify that the provided template is valid. If it is, we will continue with creating the Work Area, if it is not valid, we will exit the process.

The following shows the available Templates.

PWE - Template

# Verify the template provided is valid. If not, can the process.
if($Template = Get-PWProjectTemplates | Where-Object Name -EQ $TemplateName){
Write-Host "Validated '$TemplateName' template." -ForegroundColor Green

...  PROCESS CODE (see below).

} else {
Write-Warning -Message "Invalid template name ('$TemplateName') provided."
}

Process Code

The following is the actual code for creating the new Work Area. I like to use Splatting for easier readability.

The following shows the Target folder prior to creating new Work Area.

PWE - Target

$Splat_New = @{
InputFolder = $TargetFolder
NewProjectName = $NewProjectName
TemplateName = $TemplateName
}

<# Update the folder description for the new Work Area
if one is provided. Otherwise, it will be skipped. #>
if($NewProjectDescription.Length > 0){
$Splat_New.NewProjectDescription = $NewProjectDescription
}

<# If a StorageArea value is not provided,
use the storage area from the target folder. #>
if($StorageArea.Length > 0){
$Splat_New.StorageArea = $StorageArea
} else {
$Splat_New.StorageArea = $TargetFolder.Storage
}

try{
$PWFolder_New = New-PWRichProjectFromTemplate @Splat_New -Verbose
} catch {
Write-Warning -Message "$($Error[0].Exception.Message)"
}

The following shows the Work Area was successfully created.

PWE - New Work Area

 


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.