In this article, we are going to see how to perform operations like create, retrieve, & delete folders on SharePoint libraries using PnP PowerShell scripts. Creating a folder in a SharePoint document library gives you an efficient way to group and manage your content.
Prerequisite
Before you begin utilizing PowerShell to oversee SharePoint Online, ensure that the SharePoint Online Management Shell is installed. You can install the SharePoint Online Management Shell by downloading and running the SharePoint Online Management Shell. You only need to do this once for each computer from which you are running SharePoint Online PowerShell commands.
Connect to Site
Connect to SharePoint site using "Connect-PnPOnline" cmdlet. The required parameters are,
The following code snippet helps to connect SharePoint sites.
- $siteurl="https://<tenant-name>.sharepoint.com"
- Connect-PnPOnline -Url $siteurl
To Create A Folder on a libraryThe folders can be created on SharePoint library using “Add-PnPFolder” cmdlet on the SharePoint Site. The required parameters are,
The following code snippet helps to create the folder on SharePoint Library
- Add-PnPFolder -Name Folder1 -Folder Shared%20Documents
To Retrieve A Folder on a Library
The Folders can be retrieved on SharePoint library using “Get-PnPFolder” cmdlet on the SharePoint site. The required parameters are,
The Optional parameters are,
The following code snippet helps to retrieve folder on SharePoint Library,
- Get-PnPFolder -RelativeUrl Shared%20Documents
To Delete A Folder on a Library
The folders can be deleted on a SharePoint library by using “Remove-PnPFolder” cmdlet on the SharePoint site. The required parameters are,
The following code snippet helps to delete a folder on SharePoint Library.
- Remove-PnPFolder -Name Folder1 -Folder Shared%20Documents -Force
I hope you learned how to create, retrieve, delete folders in the SharePoint library programmatically using PnP PowerShell script. Feel free to fill up the comment box if you need any assistance.