For a long time I played with the thought: wouldn’t it be nice if we could use PnP PowerShell on other platforms than just Windows? I realize that the majority of you are most likely running Windows, but there is a (albeit minor) part of you that prefer to work on a Mac, and most likely even a smaller part runs on Linux. However, with the growth and functionality of Azure, another possible location to run your cmdlets show up: in a Docker image (which is based upon Linux for instance).
Until last year, it was not possible to do this, but then Microsoft released PowerShell as open source and that version was not based upon the .NET Framework, but based upon .NET Core: a version of the framework that actually runs as is on a Mac and on Linux.
I started to look into building a binary module for that version of the PnP Cmdlets, but pretty much ran into a blocker: CSOM only works on .NET Framework 4.X. So I dropped that approach, and experimented with a version that uses the same cmdlets towards the user, but uses the REST api behind the scenes. And that worked pretty well! It didn’t allow me the same level of authentication options, nor the flexibility the ‘normal’ version of the cmdlets provide, but it was very functional.
REST based cmdlets
I started converting the cmdlets, one by one, to use the REST api. I started with the most important one, which provides the ‘glue’ to the other cmdlets: Connect-PnPOnline. That cmdlet, in its current shape, provides tons of ways to authenticate towards your environment: credentials based, access token based, APP Only based, certificate based, etc. If you never looked into the source code of that one, do so, it’s a complex cmdlet. Using the REST api we’re a bit more limited when it comes to authentication. Or rather, I should say, without CSOM we’re more limited in what we can do. So I reverted back to the DeviceLogin approach. It works as follows (high level):