USPowerShell internal component

Previous Next

Windows PowerShell® is a task-based command-line shell and scripting language designed especially for system administration. Built on the .NET Framework, Windows PowerShell helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows. Many examples and tips can be found on the internet.

The USPowerShell internal component makes it possible to execute PowerShell® scripts from within a USoft application. It has a single method called ExecuteScript.

Syntax

INVOKE USPowerShell.ExecuteScript WITH 

SELECT     powershell-script

,          script-parameter,    value

,          ...

The required powershell-script identifies the script to be executed.

The optional script-parameter - value pairs specify parameters passed to the script. These parameters may be referred to within the script code by using the standard PowerShell® dollar-sign syntax. See the examples below.

The USPowerShell internal component is a stateful component, so any value set in a PowerShell® script can be used later in a different call to the ExecuteScript method.

In addition to the PowerShell® variables and other script parameters that are available by default, you can use a USoft-defined object called $USEngine. This object contains an instance of the USoft RulesEngine and has two methods which can be called from a PowerShell® script:

 $USEngine.ExecuteSQLQuery

 $USEngine.ExecuteSQLManipulation

 

Both methods take a SQL statement as the first parameter followed by 0 or more parameters with values that can be used inside the SQL. The values can be accessed using the placeholder notation :1, :2 ... The ExecuteSQLQuery() method returns the data retrieved. The ExecuteSQLManipulation method returns the number of rows manipulated.

The examples below demonstrate in more detail how these methods can be used in a PowerShell® script.

Examples

Example: Simple script execution

Example: Script execution with parameters

Example: Stateful test

Example: Dynamically Adding C#

Example: Converting Word to PDF

Example: Query call to the Rules Engine

Example: Manipulation call to the Rules Engine

Example: Call to the Rules Engine with variables

Example: Query call to the Rules Engine and loop through result