Calling generic static method in PowerShell

The easiest way to call MyMethod is, as @Athari says, to use MakeGenericMethod. Since he doesn’t actually show how to do that, here is a verified working code sample:

$obj = New-Object Sample

$obj.GetType().GetMethod("MyMethod").MakeGenericMethod([String]).Invoke($obj, "Test Message")
$obj.GetType().GetMethod("MyMethod").MakeGenericMethod([Double]).Invoke($obj, "Test Message")

with output

Generic type is System.String with argument Test Message
Generic type is System.Double with argument Test Message

Leave a Comment