It's fairly common in .NET to have methods with a "ref" or "out" keyword on one of the parameters. This often brings up the question: How do you call such a method from PowerShell? Fortunately, PowerShell makes this relatively simple.
The first step is understanding how to call a static .NET method from PowerShell. Let's say you have a class called "Motorcycle" like below:
public class Motorcycle
{
public Motorcycle() { }
///
/// Returns a List of all Motorcycles from the database
///
///
public static List GetAllMotorcycles()
{
List mList = new List();
// TODO: Retrieve objects from the database
return mList;
}
///
/// Gets a Motorcycle with a specific ID
///
///
public static void FindMotorcycleByID(out Motorcycle cycle, int cycleID)
{
// Load from the database
cycle = RetrieveCycle(cycleID);
}
}
[CycleProject.Motorcycle]::GetAllMotorcycles()
# Define a Motorcycle Variable
$cycle = New-Object -TypeName CycleProject.Motorcycle
# Variable for the Motorcycle ID we want to find
$motocycleID = 46
# Call FindMotorcycleById
[CycleProject.Motorcycle]::FindMotorcycleById([ref] $cycle,$motocycleID)
# Load the CycleProject assembly
Add-Type -Path "G:\Assemblies\CycleProject.dll"