#PowerShell, #PowerWiseScripting, #ProjectWise, PWPS_DAB

How To: Report on All GUI Attributes

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.

I had a request come in where a user wanted a report listing which attributes were used on each of their ProjectWise Interfaces for a specific ProjectWise Environment.

First thing I did, was create a couple of variables. One for the report path and name. And the other for the ProjectWise Environment name.

$OutputFilePathName = 'D:\Export\PWInterface_Attributes.xlsx'
$EnvironmentName = 'MyEnvironment'

Next, I created an Array list to populate with a datatable for each of the Interfaces.

$dtArray = New-Object System.Collections.ArrayList

I then looped through each of the ProjectWise Interfaces. For each of the interfaces found, I created a datatable using the Interface name as the datatable name to differentiate within the report. I then, obtained the GUI definition, and added each column/attribute name to the datatable. Finally, I added the datatable to the datatable arraylist.

foreach ($interface in (Get-PWInterfaces).Values) {
    # Create new datatable with the name of the current interface.
    $dt = New-Object System.Data.DataTable ($interface)
    # Add a column to the datatable named 'Attibute Name'.
    $dt.Columns.Add('Attribute Name')

    # Get all of the column/attribute names for the current interface.
    # Sort the column names, and add each to the datatable.
    (Get-PWInterfaceGUIDefinition -EnvironmentName $EnvironmentName -InterfaceName $interface -Verbose).'Column Name' |
    Sort-Object |
    ForEach-Object ( { $dt.Rows.Add($_) } )

    # Add the datatable to the datatable arraylist.

The final step in the process is to create the report. I used the New-XLSXWorkbook cmdlet to export all of the datatables contained in the datatable array to the Excel workbook specified in the $OutputFilePathName variable. The resulting worksheet will contain a tab for each of the interfaces contained within the ProjectWise datasource.

New-XLSXWorkbook -InputTables $dtArray -OutputFileName $OutputFilePathName -Open -Verbose

Hopefully, this all makes sense and you find it useful.

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.