Invoke Generic Methods from PowerShell

PowerShell handles .NET Generic types fairly well, but doesn't make it easy to call less common Generic methods. The Invoke-GenericMethod function allows you to call these methods with a single line of PowerShell code, without dealing with Reflection yourself.

 
 
 
 
 
5 Star
(1)
1,812 times
Add to favorites
10/25/2014
E-mail Twitter del.icio.us Digg Facebook
  • Generic method of the MongoDb driver
    1 Posts | Last post February 21, 2018
    • Hi! I just wanted to report that this module doesn't correctly work with 'FindSync' method from the latest MongoDB driver:
      
      $test = Invoke-GenericMethod -InputObject $databaseHandle -MethodName 'FindSync' -GenericType MongoDB.Bson.BsonDocument -ArgumentList $query
      Invoke-GenericMethod : No matching method was found
      
      Similarly:
      
      $test = Invoke-GenericMethod -InputObject $databaseHandle -MethodName 'FindSync' -GenericType PSOBJECT -ArgumentList $query
      Invoke-GenericMethod : No matching method was found
      
      (this method is overloaded with 3 and 4 parameters, that might be the reason, as other ones, such as GetCollection seem to be working fine)