Navigate to Site File System in SharePoint Online using PowerShell

Do you know you can navigate to 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 SharePoint Online library as a drive from PowerShell using New-PSDrive cmdlet.
$LibraryPath = "\\[email protected]\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 network drive, you can start navigating to 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

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.