Home

Using PnP PowerShell On Premises and Online

Highlighted
Joseph Ackerman
Contributor

Using PnP PowerShell On Premises and Online

I have a hybrid environment with a publishing site on premises and collaboration sites in SharePoint Online.  I have some scripts that need to run against both environments (independently, not simultaneously -- there will be one run of the script for each environment).

 

I found Erwin's article about setting up my PnP-based scripts so that they can work with either environment here:

 

https://rencore.com/blog/using-the-officedev-pnp-powershell-cmdlets-for-both-on-prem-and-in-the-clou... 

 

but it seems to be a bit out of date.  I have followed the directions about the environment variables and tried to compensate for the changes to the pathing/naming of libraries on my own, but even so I am getting errors that are keeping my scripts from running.  The first is a Warning about "unapproved verbs", and the second is that "some required components are missing" even though I just downloaded and installed both the 2016 and Online releases for March 2017. I am trying to import the pnp commands at the top of my script with this:

 

Import-Module $pnpmodulepath -Force

 

where $pnpmodulepath is a string passed in as a parameter. I am currently passing in this string:

"C:\Users\[myusername]\AppData\Local\Apps\SharePointPnPPowerShellOnline\Modules\SharePointPnPPowerShellOnline\SharePointPnP.PowerShell.Online.Commands.dll"

 

Is there any updated guidance available for writing scripts that will run on multiple environments from the same machine?

 

Thanks in advance.

2 Replies

Re: Using PnP PowerShell On Premises and Online

Okay, I figured out that I need to target the SharePointPnPPowerShell[2013|2016|Online].psd1 file and not the .DLL.  That solves the main issue above.  I also found the -DisableNameChecking parameter which got rid of the "verb" warning.

 

HOWEVER...

 

When I try running agaist 2016 on premises, Connect-PnPOnline complains:

 

Connect-PnPOnline : Method not found: 'Void Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(Microsoft.SharePoint.Client.ClientRuntimeContext, Int32, Int32)'.

 

Is there some issue with ExecuteQueryRetry in the 2016 version of the library?  I have the exact same script running against my SP Online site and it works perfectly.

 

I have triple checked that the correct 2016 module is the only one loaded.  I really need to be able to use this against an On Prem installation, so any insight will be welcome.

 

Thanks in advance.

 

Re: Using PnP PowerShell On Premises and Online

I faced the same issue and downloaded Mar release from https://github.com/SharePoint/PnP-PowerShell/releases. it worked..

Related Conversations
Updated: Online Interactive Guides
Maddie Egan  in  Online Interactive Guides  on
45 Replies
Custom markup in SharePoint calculated columns
Chris McNulty  in  SharePoint  on
11 Replies
GA: Microsoft PowerApps and Flow
Chris McNulty  in  SharePoint  on
41 Replies
Linking cells from different workbooks
Matthew Arter  in  Excel  on
4 Replies
Cost estimator for small scale catering
Louisa Dira  in  Excel  on
12 Replies
AAD PowerShell Commands not working (get-msol ...)
Ivan Unger  in  Azure Active Directory  on
16 Replies