Thursday, March 15, 2018

Switching between on-prem and SharePoint Online versions of PnP Powershell Commands

I've updated my original post to just link to these instructions. This is a better way of doing it as your explicitly loading the specific commands each time you need to run them, that way you're clear on which version you're using: 

 I use the PnP Powershell commands very frequently, but mostly only for SP Online.   Lately I've been working on a SP2013 customization and wanted to use the PnP PowerShell commands for SP2013.

If you have multiple version of the commands installed then you'll need to select which one you want to use.

This thread explains that you need to clear your PSMODULEPATH environment variables but then you'll need to an import-module when you need to work with a particular version.  Follow this guidance first:

Doing that is fine if you don't mind retyping your module path in the import, but doing it by friendly name is probably easier

Here's a quick PS command that saves you from having to manually type in the installation path:

Get-Module SharePointPnPPowerShell2013 -ListAvailable | Select Path | % { Import-Module $_.Path }

Just swap the SharePointPnPPowerShell2013 (in red) for SharePointPnPPowerShell2016 or SharePointPnPPowerShellOnline based on your needs.

Also, if you have multiple versions of the same module, you can specify which version you want to load in the Import-Module command's -RequiredVersion parameter. E.g.:

Get-Module SharePointPnPPowerShell2013 -ListAvailable | Select Path | % { Import-Module $_.Path -RequiredVersion 2.24.1803 }

If you aren't sure what flavor/versions of the commands you have simply run the first command in the pipeline with a wildcard in the module name:

Get-Module SharePointPnPPowerShell* -ListAvailable

No comments:

Restoring a lot of files from the Recycle Bin

I had a customer who accidentally synched a (very large) SP Online library and then decided they didn't want the files on their PC anymo...