#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.

13 thoughts on “HowTo: Create a Work Area from a Template”

  1. Thanks for this Brian. For some reason when I do this all my folders lose their workflows. The workflows are present in the job, just not mapped correctly? Any thoughts on what I have done wrong!

    Like

    1. Thanks for checking out my blog. I hope you find it useful.
      I don’t think you doing anything wrong. This appears to be a short-coming with the cmdlet. I would suggest posting this to the Bentley Communities ‘https://communities.bentley.com/products/projectwise/f/projectwise-powershell-extensions-forum’ site and request copying the workflows be added to the ‘New-PWRichProjectFromTemplate’ cmdlet.

      Like

      1. Thanks for the reply Brian. I will do that. Anything you can suggest to get around this?
        Would I still have this issue with the New-PWRichProjectsFromSpreadsheet option. I can’t seem to find the format needed for this spreadsheet so haven’t investigated this method really!
        I have used ‘Get-PWFolders -Slow | Export-csv -Path’ which shows the what workflows are assigned to what folders but can’t see a way to apply that back to my mew schemes folder tree!

        Like

      2. Something like the following should work for you.

        # Get full folder hierarchy for the Template Work Area used.
        $Template_Hierarchy = Get-PWFolders -FolderID $Template.ProjectID
        # Get full folder hierarchy for the NEW Work Area created.
        $Target_Hierarchy = Get-PWFolders -FolderID $PWFolder_New.ProjectID

        # Loop through all folders within the template which has a workflow assigned,
        # and update the corresponding folder within the new work area.
        foreach($f in $Template_Hierarchy | Where-Object WorkFlowID -GT 0){
        $temp = $Target_Hierarchy | Where-Object Name -EQ $f.Name
        Set-PWWorkflowByFolderPath -FolderID $temp.ProjectID -WorkflowName $f.Workflow -Verbose
        }

        Like

  2. Hi Brian,

    I have defined my template name and it is available in pw folders. But when I try to run the cmdlet of template name and if condition block, then it is throwing the else block and resulting as failure, any reason why?

    Like

      1. Hi Brian,

        Thank you!

        I am getting error as invalid template, however the template folder is there. I have also checked in PW Admin and set the template as template name.

        Any idea why it is failing to read the template name.

        Like

  3. Hello,

    Thanks for all the work you’ve put into utilizing the pwps_dab module.

    I’m having an issue with work area creation from a template where the Access Control permissions are not populating after creation completes. Is this something I’m probably doing wrong, or is it another limitation of the cmdlet?

    Thanks again,

    Like

    1. Thanks for visiting the blog. I hope you find it useful.

      I would suggest looking at the settings within PW Explorer when creating a work area. There is an option to copy access control. Is that toggled on?

      Cheers,
      Brian

      Like

  4. Hi Brian,

    I am getting message as invalid template however that template folder is already there to PW.

    Snippet:
    #Variables defined for the Name and description of new Work Area to be created.

    $NewProjectName = “70009685-Sample Deepak”
    $NewProjectDescription = “Sample Proj Created Via PowerShell”

    #Name of template to be used. This will be validated prior to continuing.

    $TemplateName = “standard_sample_template”

    <# Enter the name of the storage area to be used. Otherwise, use the target folder’s storage area. #>

    $StorageArea = [string]::Empty Select the parent folder object, where the new work area would be created.

    $TargetFolder = Show-PWFolderBrowserDialog Verify the template provided is valid. If not, cancel the process.

    if($Template = Get-PWProjectTemplates | Where-Object Name -EQ $TemplateName){
    Write-Host “Validated ‘$TemplateName’ template.” -ForegroundColor Green

    $Splat_New = @{ InputFolder = $TargetFolder NewProjectName = $NewProjectName TemplateName = $TemplateName} <# Update the folder description for the new Work Areaif 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)"}

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

    }

    I have already set the work-area template to PW admin.

    Do we have any cmdlets to pick the template by its name and store it so that it could be processed to your existing code or any other suggestion.

    Thank you!
    Regards | Deepak Singh

    Like

Leave a comment

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