#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

HowTo: Copy an Interface From One Datasource To Another

In this post, I am going to show how to copy an Interface (GUI) from one datasource (source) to a second datasource (target).  Most of us develop our ProjectWise environments and interfaces within a development or test environment. The problem is, how do you get the new interface layout to your production ProjectWise datasource? Not a problem if the Environment is new. You simply export a .aam file from the development system into the production system.  But, what if the environment already exists? The .aam file is no longer an option.  We now have this capability using PowerShell with version 1.10.5.0 of the PWPS_DAB module.

We will be using a few different cmdlets to accomplish this task. All are provided with the PWPS_DAB module. Take a few minutes to look at the help information for each of these cmdlets to familiarize yourself with the available parameters, examples, etc.

  • New-PWLogin
  • Undo-PWLogin
  • Get-PWInterfaceGUIDefinition
  • ConvertTo-DataTable
  • Set-PWInterfaceGUIDefinition

For this example, we will be using the Simple environment which is an example environment provided with ProjectWise.

The following are the two ProjectWise datasources I will be working with.

$DatasourceSource = 'BMF-WS2016:ProjectWise'
$DatasourceTarget = 'BMF-WS2016:PowerShell'

Development (Source) ProjectWise Datasource

Let’s take a look at the new Interface layout created within our development datasource.

You can see that I am logged into my ProjectWise datasource (cleverly named). I have selected the Default interface and added some attributes to it.

source

Production (Target) ProjectWise Datasource

The following shows that I am logged into my PowerShell datasource, which is my new production datasource. This datasource already has the Simple environment in place, therefore I cannot use the .aam file.

target


Update the Default Interface within the Production Datasource

Now we are going to step through the process of updating the Default interface within the Production datasource by getting the Default interface (GUI) definition from the development datasource. We will use it to update the Default interface within the Production datasource.

First, log into your Development (Source) datasource.

# Log into source datasource to get Interface definition from.
New-PWLogin -DatasourceName $DatasourceSource -UserName 'pwadmin' -Password (Read-Host -Prompt "EnterPassword:" -AsSecureString)

Prompt for secure password:

login

Use the Get-PWInterfaceGUIDefinition to extract the interface (GUI) definition for the Default interface, from the Simple environment. We will need to provide an Environment name and an Interface name.

<# Using a splat because BOTH datasources will use the same environment 
   name and interface name. #>
$Splat = @{
    EnvironmentName = 'Simple'
    InterfaceName = 'Default'
}

# Get GUI Definition to copy.
$pwGUIDef = Get-PWInterfaceGUIDefinition @Splat -Verbose

The following shows the output within PowerShell.

outputsource

The following shows the interface (GUI) definition information using the Out-Gridview cmdlet within PowerShell.

# Use the Out-GridView to see the GUI definition.
$pwGUIDef | Out-GridView

gridview

Now that we have the interface (GUI) definition, we can log out of the source datasource.

# Log out of source datasource.
Undo-PWLogin

We need to log into the target datasource.

# Log into target datasource to update the interface definition in.
New-PWLogin -DatasourceName $DatasourceTarget -UserName 'pwadmin' -Password (Read-Host -Prompt "EnterPassword:" -AsSecureString)

Next, we will use the Set-PWInterfaceGUIDefinition to import / update the Default interface within the Simple environment. This cmdlet requires a datatable for input, so we will need to convert the $pwGUIDef to a datatable.

gettype

Lets take a look at the $pwGUIDef datatype.

<# The returned object type using the Get-PWInterfaceGUIDefinition is a 
    PowerShell object. The Set-PWInterfaceGUIDefinition only accepts a
    datatable. So, we'll need to convert it. #>
$pwGUIDef.GetType()

datatype1

If you do not convert the $pwGUIDef to a datatable and you attempt to run the Set-PWInterfaceGUIDefinition cmdlet, you will receive the following error.

errror

We will now convert the $pwGUIDef to a datatable and look at the datatype once again.

# Convert $pwGUIDef from a PowerShell object to a datatable.
$pwGUIDef = ConvertTo-DataTable -InputObject $pwGUIDef -Verbose

# Show type after converting to a datatable.
$pwGUIDef.GetType()

datatype2

Now that we have converted the $pwGUIDef to the correct datatype, we can update the Default interface within the target datasource.

Let’s ensure we are in the correct datasource first.

# Get the name of the current ProjectWise datasource.
Get-PWCurrentDatasource

datasource

We are logged into the correct datasource, so let’s run the Set-PWInterfaceGUIDefinition cmdlet.

# Set Gui definition for the interface specified within the specified Environment.
Set-PWInterfaceGUIDefinition -GUIDefinition $pwGUIDef @Splat -Verbose

The following shows the output within PowerShell.

output

Finally, lets look at the Default interface (GUI) within the target datasource. Looks good to me.

result

 


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.