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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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