Posts

Set up Enterprise App to use App-Only Sites.Selected permissions and wite to SharePoint with PnP Powershell

I wanted to run unattended scripts against SharePoint for various governance and content cleanup jobs and found the guidance for this to be a little confusing.   I think it's a good idea to limit the access of any script, so I prefer to set up an App per script and use the Sites.Selected permission to limit the sites to which my app has access.   Here's the process I used to get it to work: You can register an app in the Azure portal UI, but there's a few steps that must be performed with PowerShell, so I figured just doing it all in Powershell made it consistent.   Step 0:  Get the right version of PnP.Powershell I also had to use the PnP.PowerShell 2.2.81 nightly build because there was a bug introduced in 2.2.0.  If you need to get a specific version you can run Install-Module, but I prefer to use Save-Module with specific version  so I can keep different version of PnP.PowerShell around to avoid having my old scripts affected by new modules and potential regression issu

Quick SPFx Dev Environment Setup Guide

This is just a quick post to document my current setup steps Install NVM for windows Install the proper version(s) of node using nvm install VersionNum (see https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment for currently supported versions) Address any critical vulnerabilities Install yeoman and spfx genereator npm i -g yo npm i -g @microsoft/generator-sharepoint Install additional utils Install gulp npm i -g gulp Install Git Install VS COde Test yo @microsoft/sharepoint

Show Document LIbrary from another site collection on a Modern SharePoint Page

Here's a pretty good workaround for the lack of a cross-Site Collection Document library and not having to go to a fancy search interface or develop or buy an SPFx component.   Keep in mind that the user who's visiting the site where you're surfacing the library will need at least read access to the library. Go to the document library you'd like to surface, then go to the folder, etc. with the information you'd like to share. Copy the URL from the address bar. On the Modern Page/site where you'd like to show that document library/folder, add an Embed Web Part Add the following to your embed web part: <iframe src="URLYOUCOPIEDINSTEP1" width="100%" height="600"></iframe> This experience allows people to navigate the library/folders without leaving the site they are on, but the docs open in their own tab.

Power Automate: Using the SharePoint Update Item action

Power Automate's Update Item action for SharePoint has an issue with choice fields in that when you add that action, all fields are blank EXCEPT Choice fields.  Choice fields will instead default to the top item in the choice list.   This is really bad because if you don't clear them the flow will overwrite any existing values with the top items. Currently, the only way I can see to avoid this issue is to manually clear each field, so here are the steps: Choose the dropdown item on the choice field. Choose "Enter Custom Value" Immediate go back to the field and click the 'X' in the field and it will be cleared Repeat for each choice field that you don't want to change. I think the above is just a hack/workaround to a problem with how this action is configured by default so I put this into the uservoice/suggestion box for PowerAutomate.    Upvote this if you think it's worth it: https://powerusers.microsoft.com/t5/Power-Automate-Ideas/SharePoint-Update-

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 anymore...so they deleted them and were shocked to learn that they'd been deleted from SharePoint too! Thanks to PnP Powershell you can use the following to restore a batch of files quickly (and filter). First, you'll want to make sure you only select the files you want to restore.  I used a combination of filtering by the person who deleted the files and the date they were deleted, e.g. Connect-PnPOnline https://yourtenanturl $restoreSet = Get-PnPRecycleBinItem | Where-Object { $_.DeletedByEmail -eq "imsorry@company.com" -and $_.DeletedDate -gt "1/1/2019" } Make sure you have a fairly updated version of the PnP Powershell module as the objects that come back have more properties populated than in older versions so you can do more powerful filtering Next you can restore the files like this: $restoreSet | Rest

Scoped Bootstrap for SharePoint

I've got a project for a client that involves refactoring a lot of bad choices related to SharePoint branding in Classic mode sites.   (While I'm enthusiastic about the Modern Sites and new techniques using SPFx extensions, most of our customers are slow on the uptake). I've had to do this a few times and this blog explains it perfectly, but due to some formatting issues over there and a desire for just the steps as I need to update/repeat this, I've summarized here: Open up a node capable command prompt (I use cmd) Create a directory for your solution (e.g. C:\Repos\ScopedBootstrap) Run npm install bootstrap@3.3.7 (or whatever version you need to work with) Go into the node_modules\bootstrap\less directory  Open bootstrap.less in VS Code. Place  .YourUniqueClassName{  before all the @import statements and close the curly brace at the end of the file. Go back to the ..\bootstrap directory (in node_modules) Run npm install to install the dependencies Run

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 you're explicitly loading the specific commands each time you need to run them, that way you're clear on which version you're using: https://www.erwinmcm.com/running-the-various-versions-of-pnp-powershell-side-by-side/   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:  https://github.com/SharePoint/PnP-PowerShell/issues/1356 Doing that is fine if you don't mind retyping your module path in the i