Using PnP PowerShell On Premises and Online

%3CLINGO-SUB%20id%3D%22lingo-sub-54218%22%20slang%3D%22en-US%22%3EUsing%20PnP%20PowerShell%20On%20Premises%20and%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-54218%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20hybrid%20environment%20with%20a%20publishing%20site%20on%20premises%20and%20collaboration%20sites%20in%20SharePoint%20Online.%20%26nbsp%3BI%20have%20some%20scripts%20that%20need%20to%20run%20against%20both%20environments%20(independently%2C%20not%20simultaneously%20--%20there%20will%20be%20one%20run%20of%20the%20script%20for%20each%20environment).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20found%20Erwin's%20article%20about%20setting%20up%20my%20PnP-based%20scripts%20so%20that%20they%20can%20work%20with%20either%20environment%20here%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Frencore.com%2Fblog%2Fusing-the-officedev-pnp-powershell-cmdlets-for-both-on-prem-and-in-the-cloud%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Frencore.com%2Fblog%2Fusing-the-officedev-pnp-powershell-cmdlets-for-both-on-prem-and-in-the-cloud%2F%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebut%20it%20seems%20to%20be%20a%20bit%20out%20of%20date.%20%26nbsp%3BI%20have%20followed%20the%20directions%20about%20the%20environment%20variables%20and%20tried%20to%20compensate%20for%20the%20changes%20to%20the%20pathing%2Fnaming%20of%20libraries%20on%20my%20own%2C%20but%20even%20so%20I%20am%20getting%20errors%20that%20are%20keeping%20my%20scripts%20from%20running.%20%26nbsp%3BThe%20first%20is%20a%20Warning%20about%20%22unapproved%20verbs%22%2C%20and%20the%20second%20is%20that%20%22some%20required%20components%20are%20missing%22%20even%20though%20I%20just%20downloaded%20and%20installed%20both%20the%202016%20and%20Online%20releases%20for%20March%202017.%20I%20am%20trying%20to%20import%20the%20pnp%20commands%20at%20the%20top%20of%20my%20script%20with%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EImport-Module%20%24pnpmodulepath%20-Force%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhere%20%24pnpmodulepath%20is%20a%20string%20passed%20in%20as%20a%20parameter.%20I%20am%20currently%20passing%20in%20this%20string%3A%3C%2FP%3E%3CP%3E%22C%3A%5CUsers%5C%5Bmyusername%5D%5CAppData%5CLocal%5CApps%5CSharePointPnPPowerShellOnline%5CModules%5CSharePointPnPPowerShellOnline%5CSharePointPnP.PowerShell.Online.Commands.dll%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20any%20updated%20guidance%20available%20for%20writing%20scripts%20that%20will%20run%20on%20multiple%20environments%20from%20the%20same%20machine%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-59121%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20PnP%20PowerShell%20On%20Premises%20and%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-59121%22%20slang%3D%22en-US%22%3E%3CP%3EI%20faced%20the%20same%20issue%20and%20downloaded%20Mar%20release%20from%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Freleases%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Freleases%3C%2FA%3E.%20it%20worked..%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-54283%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20PnP%20PowerShell%20On%20Premises%20and%20Online%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-54283%22%20slang%3D%22en-US%22%3E%3CP%3EOkay%2C%20I%20figured%20out%20that%20I%20need%20to%20target%20the%26nbsp%3BSharePointPnPPowerShell%5B2013%7C2016%7COnline%5D.psd1%20file%20and%20not%20the%20.DLL.%20%26nbsp%3BThat%20solves%20the%20main%20issue%20above.%20%26nbsp%3BI%20also%20found%20the%20-DisableNameChecking%20parameter%20which%20got%20rid%20of%20the%20%22verb%22%20warning.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHOWEVER...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20try%20running%20agaist%202016%20on%20premises%2C%20Connect-PnPOnline%20complains%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConnect-PnPOnline%20%3A%20Method%20not%20found%3A%20'Void%20Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(Microsoft.SharePoint.Client.ClientRuntimeContext%2C%20Int32%2C%20Int32)'.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20some%20issue%20with%20ExecuteQueryRetry%20in%20the%202016%20version%20of%20the%20library%3F%20%26nbsp%3BI%20have%20the%20exact%20same%20script%20running%20against%20my%20SP%20Online%20site%20and%20it%20works%20perfectly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20triple%20checked%20that%20the%20correct%202016%20module%20is%20the%20only%20one%20loaded.%20%26nbsp%3BI%20really%20need%20to%20be%20able%20to%20use%20this%20against%20an%20On%20Prem%20installation%2C%20so%20any%20insight%20will%20be%20welcome.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

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
Highlighted

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.

 

Highlighted

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