Muhammad Murad Haider
Muhammad Murad Haider

Reputation: 1477

Using SharePoint Online Client components (Microsoft.SharePoint.Client) with powershell 2.0

I am trying to create data in SharePoint lists using PowerShell. I have the script ready which works fine with PowerShell 3.0 and PowerShell 4.0. But when I try running the script using PowerShell 2.0 it can not load the assembly as mentioned in title and throws error right in the start of script execution.

Could not load file or assembly 'path\Microsoft.SharePoint.Client.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Is it possible to achieve the goal using PowerShell 2.0 without upgrading to PowerShell 3 or 4?

Upvotes: 1

Views: 815

Answers (1)

tinamou
tinamou

Reputation: 2292

Short answer, no.

PowerShell 2.0 was built with .NET 2.0 and it can not load DLL built with .NET 4.0

Here is more exception description: BadImageFormatException

The exception says it all, but here is some more documentation on PowerShell requirements: Windows PowerShell System Requirements

To authenticate to SharePoint Online, almost in every code sample there is SharePointOnlineCredentials class used, which is part of Microsoft.SharePoint.Client which is .NET 4.

But, it is possible to authenticate to SharePoint Online REST API using Token. Here some information from stackexchange: How to authenticate to SharePoint Online (Office 365) using REST API

The last option is to use direct username\password with federated authentication. I'm also not familiar if there is a corresponding library for JAVA, I can only give you an example in nodejs from here. In short, you need to POST preconfigured SAML XML to MS Online Security Token Service (STS), receive encoded token and exchange it to auth cookie with SharePoint Online. You can use a fiddler to see the actual requests.

nodejs code example: OnlineUserCredentials.ts

And about tokens: SharePoint Online (O365) OAuth Authentication | Authorizing REST API calls against SharePoint Online Site | Get Access token from SharePoint Online | Set up OAuth for SharePoint Online Office 365

Upvotes: 2

Related Questions