Hello, Object reference not set to an instance of an object, my old friend. Good to see you again.

Recently attempting to apply a PnP Tenant Template to an environment and ran into the above non-descript error message:

Apply-PnPTenantTemplate -Path C:\temp\client\provisioning\client.xml -Parameters @{"SiteURL"="https://clienttenant.sharepoint.com/sites/targetsite"} -Verbose

Apply-PnPTenantTemplate : Object reference not set to an instance of an object.
At line:1 char:1
+ Apply-PnPTenantTemplate -Path C:\temp\client\provisioning\client.xml -Para ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Apply-PnPTenantTemplate], NullReferenceException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.Tenant.ApplyTenantTemplate

I reached out the the dev team and asked for some support - it's great to have a solid dev team - and they asked me to confirm that I'm running the latest version of the SharePointPnPPowerShellOnline module. They were nice enough to provide a PowerShell one-liner to do just this:

Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending

Now this isn't my first rodeo, so I updated the module specifying the -AllowClobber and -Force parameters. Following that I re-ran the Apply-PnPTenantTemplate cmdlet - it failed again.

Time to figure out exactly what version of SharePointPnPPowerShellOnline I had installed:

Name                          Version
----                          -------
SharePointPnPPowerShellOnline 3.9.1905.3
SharePointPnPPowerShell2016   3.9.1905.3
SharePointPnPPowerShellOnline 3.0.1808.1
SharePointPnPPowerShellOnline 2.27.1806.1
SharePointPnPPowerShell2016   2.27.1806.0
SharePointPnPPowerShell2016   2.25.1804.1

Not only did I have the latest installed, but I'd managed to side-by-side install it with prior versions - that's the -AllowClobber and -Force at work. The result of this seems to create a scenario where certain commands are executed by prior versions of the same module, and this case that made for a failed deployment.

The fix was to run Uninstall-Module for the offending versions and then retry the Apply-PnPTenantTemplate. For the future, I'm going to look at Using SharePoint PnP PowerShell Modules Side-by-Side as Chris Kent details on his blog.