How to Map a SharePoint Online Document Library as a Network Drive using PowerShell?

Requirement: Map a network drive to a SharePoint Online library.

How to map a network drive in SharePoint Online?

At times, You may need to manage/upload/download files and folders in bulk using Explorer view, and mapping SharePoint Online document library as a network drive is necessary to manage the SharePoint folder structure efficiently in the long run. Here is how to map a network drive to the SharePoint Online document library:

  1. Go to Windows Explorer on your computer >> Right Click on “Computer” (or “This PC”) >> Choose “Map to network drive”.
    powershell to map sharepoint online document library as network drive
  2. Select the drive letter you want to use >> Enter the URL of your SharePoint Online document library.  E.g. Your SharePoint library URL could be: You can also enter the site URL to map a SharePoint Online site as a network drive.
  3. Choose “Reconnect at logon”, “Connect using different credentials” options according to your requirements, and click on the “Finish” button. You may get a login prompt.
    map network drive in sharepoint online
  4. This creates a new network drive mapping for the given SharePoint Online document library URL. Now you can access SharePoint online document library from Windows Explorer

Common Errors and Solutions:

Error: “The mapped network drive could not be created because the following error has occurred. Access Denied. Before opening files in this location, you must first add the web site to your  trusted sites list, browse to the web site, and select the option to login automatically.”

Solution: Make sure your SharePoint Online site URL is added under the “Trusted Sites” zone of the browser security settings and the Trusted sites zone has “Automatically Login with current user name and password” configuration set! Also, the “Web Client” Service must be started in Services console (Services.msc). Otherwise, You may get the below error message! This error also happens when the user sessions expired! Just login to SharePoint through web browser to re-establish the session.

access denied. before opening files in this location, you must first add the web site to your trusted sites list

If you get the same error event after setting above configurations, apply this KB: Error when you open a SharePoint Document Library in Windows Explorer or map a network drive

Users must have at-least “Read-only” permission to the Site level to be able to open the document library in Explorer view! So, if you granted them access at the file/folder/library level, Add them to site-level too!

access denied. before opening files in this location you must first add the web site to your trusted sites list

Here is the Microsoft article on troubleshooting issues with mapping network drive: Troubleshoot mapped network drives that connect to SharePoint Online

PowerShell to map a network drive in SharePoint Online

To Map a SharePoint Online Document library to a network drive using PowerShell,

$LibraryPath = ""

#Map Path as Network Drive
$Network = new-object -ComObject WScript.Network
$Network.MapNetworkDrive('R:', $LibraryPath)

Once its executed successfully, you can see the given path mapped as network drive from File explorer.

You can use New-PSDrive cmdlet to access the file system location that can be a remote or on a local computer.

$LibraryPath = "\\[email protected]\DavwwwRoot\Sites\p\Salaudeen"

#Virtually map SharePoint Online Folder as PSDrive
New-PSDrive -name "R" -Root $LibraryPath -PSProvider filesystem

This doesn’t appear in File explorer, But you can access it through PowerShell.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

4 thoughts on “How to Map a SharePoint Online Document Library as a Network Drive using PowerShell?

  • August 14, 2021 at 1:30 AM

    Will this method work even with the end of Microsoft 365 support in Internet Explorer?

    • September 9, 2021 at 11:05 AM

      This feature depends on WebDav! I tested it in a PC without Internet Explorer and found it works.

  • July 23, 2021 at 6:28 PM

    I am getting below error

    The network name cannot be found.
    At C:\Users\Rakesh.Menon\Desktop\MapNetworkDrive.ps1:23 char:1
    + $net.MapNetworkDrive($drive, $LibraryPath, “true”)#, $user, $cred.Get …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException

    • September 9, 2021 at 11:08 AM

      Looks the $LibraryPath is not resolved! Check if you are able to browse to it.


Leave a Reply