D/3 Tips & Tricks: PowerShell Description

PUBLISHED ON Nov 02, 2010

Using Windows PowerShell and D3Client to retrieve, organize, and display data from a D/3®

PowerShell and its associated scripting language offer a number of advantages over the traditional DOS command shell. For example, tasks that would typically require DOS batch files, VBScript files, and/or compiled programs can now be done with PowerShell scripts. Additionally, the PowerShell scripting language is object-oriented, is similar to C#, and is fully integrated with the .NET Framework. Each variable in the PowerShell scripting language is treated as an object with associated properties and methods.

This first example shows how data is retrieved using a D3Client call in a traditional DOS console:

 

 

The next example shows the same D3Client call executed in PowerShell. Results are now stored in the “$obj” PowerShell object, and the contents of $obj are displayed in the PowerShell console. Note that the variable $obj has text values from the D3Client call stored in a string array. The $obj object also has methods and properties associated with the string array object type. In this case, the D3Client call is retrieving an EPN list for the Sequence Database (SDB) unit EVAP11.

 

Slightly more sophisticated, the next example shows the results of the get-d3client function. This is a custom function that gathers and displays data based on input from the user. In this case, the user asked for the AI EPN list from the EVAP11 SDB unit. The function performs the following:

 

  • Parses the input field and generates a D3Client call.
  • Stores the returned data from D3Client into an Arraylist object.
  • Filters out the diagnostic information.
  • Returns (displays) the filtered data object.

 

 

Let’s say that a user wanted to analyze the IPN structure of a D/3 Sequence Database Unit. The example below shows the results of the get-sdbUnit function. This function gathers the entire EPN list for a SDB unit and displays the results in tabular format for easy analysis. This function performs the following:

 

  • Creates four D3Client calls for the AI, DIN, DOT and DEV EPN lists.
  • Stores data in string arrays ($aiList, $dinList, $dotList, and $devList).
  • Adds a “space” delimiter to the data in all arrays, separating the unit relative IPN, EPN Name, and absolute IPN for each record.
  • A custom array object is created for each data type (AI, DIN, DOT, DEV), then displayed as a table.

 

 

The function get-sdbUnit also has a summary option.  Instead of displaying each AI, DIN, DOT, and DEV EPN in a table, the function can also return the number of each type of IO, the first IPN of each type of IO, and the number of spare IPNs for each type of IO.  The function performs the following:

 

  • Creates 4 d3client calls for the AI, DIN, DOT and DEV EPN lists.
  • Stores data in string arrays ($aiList, $dinList, $dotList, and $devList).
  • The number of IPNs for each IO type is determined by using the Count() method.
  • The first IPN for each IO type is determined by splitting the first string in each IO type array and retrieving the absolute IPN.
  • The number of spare IPNs for each IO type is determined by filtering out the number of strings in each IO type string array that contain the word “spare”, then counting the number of elements in the filtered string array using the Count() method.

 

This final example shows the result of the execution of “get-sdbUnit EVAP11 –summary”.

 

The PowerShell script for these examples may be downloaded from the NovaTech Automation Process Support Website. The Customer Support Website is password protected, if you do not have a Customer User Name and Password, please contact cchelp@novatechweb.com.