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 New-PSDrive cmdlet.
#Variable $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 a network drive, you can start navigating to the site file system and manipulate it. For E.g. Let’s copy a folder with its content in a SharePoint Online document library.
#Switch to Mapped Drive M: #Change Current Directory to "Branding" Folder CD Branding #Get the contents of the Folder Dir #Copy a Folder with its contents Copy 2019 -Destination 2020 -Recurse
Here is the entire flow: