Example: Dynamically adding C#

Previous Next

Here is an example of how the PowerShell script functionality may be extended by adding C# code:

INVOKE USPowershell.ExecuteScript

WITH

SELECT 'Add-Type -Language CSharpVersion3 -TypeDefinition @"

using System;

 

public class Class1

{

    public static String MyMethod()

    {

       return "Hello World!";

    }

}

"@';

 

INVOKE USPowershell.ExecuteScript

WITH

SELECT 'Write-Output([Class1]::MyMethod())'

 

This results in:

Hello World!

Since USPowershell is a stateful component, once the Class has been added, it remains available for later use.

 

See also

Example: Simple script execution

Example: Script execution with paramaters

Example: Stateful test

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

USPowerShell