#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Create Work Area and Connected Project

In this post, we will be stepping through the process of creating a new Work Area using the New-PWRichProject cmdlet and an associated Connected Project using the Add-PWConnectedProject.  We will also be using few other Connected Project related cmdlets for data validation and to obtain a token which is required for all of Connected Project cmdlets we will be using.

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

  • New-PWRichProject
  • Get-PWConnectionClientToken
  • Get-PWConnectedProjectAssetTypes
  • Get-PWConnectedProjectDataLocations
  • Get-PWConnectedProjectIndustryTypes
  • Add-PWConnectedProject

Defining Variables

Before we get started, we will be creating some variables to be used for creating the Work Area and the Connected Project. 

#region VARIABLES

# Variables for creating the Work Area.
# Fullpath and name of the Work Area to create.
$NewFolderPath = 'Projects\MyNewProject'
# Storage area to be used. Required.
$StorageArea = 'Storage02'
# Work Area type to be used. Required.
$ProjectType = 'General'

# Variables for creating the Connected Project.
$ConnectedProjectNumber = '123456-BMF'
$ConnectedProjectName = 'BMF-MyNewProject'
$AssetType = 'Process Manufacturing Plant'
$DataLocation = 'East US'
$Industry = 'Buildings And Facilities'
$Location = 'Navarre, FL'
$CountryCode = 'USA'

#endregion VARIABLES

Create Work Area

Now, we will create a new Work Area within our ProjectWise datasource. There are multiple ways to create a new Work Area, however we will be using the New-PWRichProject cmdlet.

#region CREATE WORK AREA

$Splat_NewWorkArea = @{
NewFolderPath = $NewFolderPath
StorageArea = $StorageArea
ProjectType = $ProjectType
}
$newWorkArea = New-PWRichProject @Splat_NewWorkArea -Verbose

#endregion CREATE WORK AREA

The following shows the contents of the Splat prior to running the cmdlet.

splat_newworkarea

The following shows the new Work Area we just created. Notice there is not a Connected Project associated with it.

newworkarea

Get Required Token

We will now get a token to be used with the Connected Project cmdlets.

# Get required Token to create new Connected Project.
$Token = Get-PWConnectionClientToken

Validate Variable Entries

This section is not required. However, I like to verify my data prior to running any cmdlets. Each of the validation variables will be populated with a true or false indicating success or failure. These variables will be used when populating the Splat to create the Connected Project.

#region VARIABLE VALIDATION

# Used to validate the provided Asset type.
$validateAssetType = if( Get-PWConnectedProjectAssetTypes -Token $Token |
Where-Object {$_ -eq $Type}) { $true } else { $false }

# Used to validate the provided Data Location.
$validateDataLocation = if( Get-PWConnectedProjectDataLocations -Token $Token |
Where-Object { $_ -eq $DataLocation }) { $true } else { $false }

# Used to validate the provided Industry.
$validateIndustry = if( Get-PWConnectedProjectIndustryTypes -Token $Token |
Where-Object { $_ -eq $Industry }) { $true } else { $false }

#endregion VARIABLE VALIDATION

Populate the Splat

Here we will be populating the Splat to be used to create the Connected Project. We will be using the previously populated validation variables to determine whether some parameters should be included.

#region POPULATE SPLAT

$Splat_NewConnectedProject = @{
InputFolder = $newWorkArea
Token = $Token
ConnectedProjectNumber = $ConnectedProjectNumber
ConnectedProjectName = $ConnectedProjectName
Location = $Location
CountryCode = $CountryCode
}

if($validateAssetType){
# Removing spaces to conform to allowed AssetType values.
$Splat_NewConnectedProject.AssetType = $($AssetType.Replace(' ', ''))
}
if($validateDataLocation){
$Splat_NewConnectedProject.DataLocation = $DataLocation
}
if($validateIndustry){
# Removing spaces to conform to allowed Industry values.
$Splat_NewConnectedProject.Industry = $Industry.Replace(' ', '')
}

#endregion POPULATE SPLAT

The following shows the contents of the Splat prior to running the cmdlet.

splat_newconnectedproject

Create Connected Project

Finally, we will be creating the Connected Project using the populated Splat.

#region CREATE CONNECTED PROJECT

# Create new Connected Project and associate it with the provided Work Area.
$NewConnectedProject = Add-PWConnectedProject @Splat_NewConnectedProject -Verbose

#endregion CREATE CONNECTED PROJECT

The following images show the newly created Connected Project.

newconnectedproject

The following shows the Connected Project has been successfully associated with the Work Area.

newworkarea2workareaproperties


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 )

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.