Navigate to Site File System in SharePoint Online using PowerShell

Do you know you can navigate to the site file system using SharePoint Online from PowerShell? Well, Here is how it works:

Create a Mapped Drive for SharePoint Online site or Library

To start with, we’ve to map the SharePoint Online library as a drive from PowerShell using the New-PSDrive cmdlet.

$LibraryPath = "\\\DavwwwRoot\Sites\marketing"
#Virtually map SharePoint Online Folder as PSDrive
New-PSDrive -name "M" -Root $LibraryPath -PSProvider filesystem

This doesn’t appear in File Explorer, But you can access it through PowerShell. You can also create a persistent drive with -Persist switch.

Access Mapped Drive through PowerShell

Once the library or site is mapped as a network drive, you can navigate the site file system and manipulate it. E.g., let’s copy a folder with its content in a SharePoint Online document library.

#Switch to Mapped Drive

#Change Current Directory to "Branding" Folder
CD Branding

#Get the contents of the Folder

#Copy a Folder with its contents
Copy 2019 -Destination 2020 -Recurse

Here is the entire flow:

navigate site file system using sharepoint online powershell

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *