views:

262

answers:

1

I need to use the SharePoint API in the following way in a PowerShell script:

C# Code:

var service = farm.Services.GetValue<SPWebService>();

How does one specify the generics parameter in PowerShell?

At the moment I get an Exception stating that "Late bound operations cannot be performed on types or methods for which ContainsGenereicParameters is true"

+4  A: 

This is not something you can easily do. You will have to resort to Reflection to make that work. See this blog post for more information.

Mark Seemann
Thanks for the link. I was able to come up with the following solution:[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local$method = [Microsoft.SharePoint.Administration.SPServiceCollection].GetMethod("GetValue", [string])$closedmethod = $method.MakeGenericMethod([Microsoft.SharePoint.Administration.SPWebService])$service = $closedmethod.Invoke($farm.Services, "")
Ries