Thursday, March 15, 2018

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

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

Wednesday, November 8, 2017

Client Side Override the Site Logo's link in an SharePoint Site

In SharePoint sites that have any kind of hierarchy of subwebs, it is frequently desirable to override the logo's link behavior to link back to the root of the site collection.   There's a bunch of guidance on how to do this by overriding the master page, but not much on how to do this client-side, to avoid MasterPage manipulation.   Here's a script that helps to do this:

//update site icon link, SP overrides any direct reassignment so you have to change the existing ID
//and then create a dummy element with the existing ID to avoid future JS errors.
//read old link id
var prevId = $("#DeltaSiteLogo > a").attr('id');
//change the id
$("#" + prevId).attr({
      'title': 'Employee Portal Home',
      'href':window.location.protocol + "//" +
$("#DeltaSiteLogo > a").after("<a id='" + prevId + "' href='#' style='display:none'>Dummy</a>");

You'll need jQuery to do this and I'd recommend putting this into a file and then injecting via a SiteCollection scope custom action.   Here's the simplest way to do that: 

Wednesday, March 29, 2017

Connect-PnPOnline : For security reasons DTD is prohibited in this XML document. error

Until today I had never received this error when trying to connect to SPO.    If you get this error there's a good chance it's related to missing records on the DNS server your machine is relying upon.  If not set, there's a good chance you're using your ISP's DNS servers, whose records may not be as up to date as others.  The quick fix (at least for me) was to alter my DNS settings to point to more reliably up-to-date DNS.   Here's a how to fix this issu (on Windows 10, if you aren't using windows 10, follow your OS instructions on updating DNS settings and then just jump to step 4 below) along with a few options for DNS settings that I tested:

  1. Click Start and type "View Network Connections.
  2. Right-Click your adapter that connects to the internet and choose properties
  3. Choose TCP/IP v4 and then click the "Properties" button
  4. At the bottom of the IP v4 properties window, select the radio button that says "Use the following DNS Server addresses" and enter in a primary and secondar DNS.
    1. You can view a recently updated list of options here: 
    2. FWIW, I chose Google's, Primary: and Secondary:
  5. Click OK out of all the windows and retry the Connect-PnP (or Connect-SPO) command.