When it comes to using SharePoint 2010 Client Object Model (CSOM) we need to be ready for certain kind of limitations in PowerShell. First of all, it concerns the usage of Generics Methods, for the example ClientRuntimeContext.Load<T> method:
An attempt to call the method ClientRuntimeContext.Load<T> directly will result in the following error
This is a limitation of PowerShell (V1, V2) AFIK. There are several options how to bypass this limitation but in this post I would like to concentrate only on one technique that was originally described in the post Invoking Generic Methods on Non-Generic Classes in PowerShell. The basic idea is to replace the call for ClientRuntimeContext.Load<T> method with the following one:
Example: load Web client object
Let’s start with a simple example for loading Web Client Object:
Example: create Wiki page via CSOM
The example below demonstrates how to create wiki page via CSOM.
In contrary to article Using PowerShell to Get Data from a SharePoint 2010 List that explains how to execute generic methods via inline C# in PowerShell, this post demonstrates how to utilize Generics Methods in PowerShell natively.
- Invoking Generic Methods on Non-Generic Classes in PowerShell
- Using PowerShell to Get Data from a SharePoint 2010 List