Get files with specific names in SharePoint using PowerShell
It’s not uncommon for companies to be wanting an inventory of files / folders in SharePoint. But we can also narrow down the request, and look for only specific documents?
In this blog post, we’ll have a look at how to retrieve all the documents with particular name(s), from a Site. Maybe you have a naming convention for files / folders, and therefore, it’s easier to target.
Current documents in a Site
As a proof (although technically, you can only take my word for it), I’ll run a script to check ALL the documents I have in my site… In the image below, we can see that I have multiple documents, on different document libraries.
So our goal today, is to retrieve all the documents with the letters “ABC” or “BCD” in their name.
Get all the specific documents
As usual, we’ll start by connecting to SharePoint Online using the
Connect-PnPOnline cmdlet, we’ll store in a variable the path for our output file, and also store all the document libraries in another variable using the
Then, we will:
- Store all the documents in
$AllItemsand expose a few fields
- Create a
IFstatement –> if the file is like “ABC” or “BCD” (note the asterisks ABC for a wider search)
- And finally, export the results to our
Thanks for reading!