How to Map Network Drives with PowerShell in Windows 11

This article shows you how to map or unmap network drives using PowerShell in Windows 11.

Windows PowerShell is a tool that helps you automate tasks on your computer. It includes a command-line shell and a scripting language. The app comes built-in with Windows.

There are multiple ways you can map or unmap network drives in Windows. You can use File Explorer, the Command Prompt, or PowerShell app.

How to Map a Network Drive Using PowerShell

To map a network drive using PowerShell in Windows 11, follow these steps:

  1. Open PowerShell by searching for it in the Start menu.
  2. Type this command into PowerShell:

    New-PSDrive -Name "DriveLetter" -PSProvider FileSystem -Root "\\Server\Share"
  3. Replace "DriveLetter" with the letter you want to assign to the network drive (for example, Z). Replace "\\Server\Share" with the UNC path of the share you want to map (for example, "\\myserver\myshare").

That’s the basic PowerShell command format for mapping network shares in Windows.

Map or Unmap Network Drives in PowerShell

As mentioned above, you have multiple ways to map or unmap (disconnect) network drives in Windows.

Usually, users will use File Explorer to map or disconnect a network drive. However, PowerShell can also map or unmap (disconnect) network drives.

Here’s how to do that.

Step 1: Open PowerShell

  1. Click on the Start Menu and search for PowerShell.
  2. Under Best match, select and open the PowerShell app. The Windows Terminal app will open with a PowerShell prompt.

Note: Do not run the terminal as an administrator. This allows the mapped drive to appear in File Explorer.

Step 2: Type the Mapping Command

In the terminal window, type this command:

New-PSDrive -Name "DriveLetter" -PSProvider "FileSystem" -Root "\\ServerName-or-IPAddress\SharedFolder" -Persist

Replace DriveLetter with a drive letter you want to use. Replace ServerName-or-IPAddress and SharedFolder with the server computer’s name (or IP address) and shared folder name.

Example:

New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root "\\192.168.1.100\Documents" -Persist

If prompted for a username and password, type them correctly and press Enter to map the network share.

Step 3: Add Credentials (Optional)

When you connect to a protected share, you will be prompted for a username and password. To avoid typing your password every time, you can store it with the command.

Option A: Store Credentials in a Variable

  1. First, run this command to store your credentials:

    $cred = Get-Credential -Credential USERNAME

    Replace USERNAME with your account name or username.
  2. A prompt window will appear. Type in your password and click Ok to store your credentials.

    Windows 11 use PowerShell to map network drives
  3. Now run this command to map the network drive with your stored credentials:

    New-PSDrive -Name "E" -Root "\\192.168.1.100\Documents" -Persist -PSProvider "FileSystem" -Credential $cred

Option B: Store Credentials in Credential Manager

Alternatively, store your credentials in the Credential Manager by running this command:

cmdkey /add:192.168.1.100 /user:WORKGROUP\username /pass:password

Replace WORKGROUP with your domain or workgroup name. Replace 192.168.1.100 with the computer name that has the shared folders. Replace username and password with your account details.

After storing your credentials in the Credential Manager, you can run the PowerShell command without typing your credentials:

New-PSDrive -Name "P" -Root "\\192.168.1.100\Documents" -Persist -PSProvider "FileSystem"

Unmap or Disconnect Network Drives Using PowerShell

Once a shared drive is mapped, you can use PowerShell to unmap or disconnect it.

Step 1: List All Mapped Drives

Before you disconnect a shared network drive, you may want to see all the mapped drives on your computer. Run this command:

Get-PSDrive -PSProvider "FileSystem"

Step 2: Disconnect a Single Drive

Once you know the letter used to map the drive, run this command to unmap or disconnect it:

Remove-PSDrive -Name DriveLetter

Replace DriveLetter with the drive letter you want to disconnect.

Example:

Remove-PSDrive -Name Z

Step 3: Disconnect Multiple Drives

To disconnect more than one drive at a time, run this command:

Get-PSDrive X, W | Remove-PSDrive

That’s it! Your mapped drives are now disconnected.

Summary

Why use PowerShell to map network drives? PowerShell gives you a fast and powerful way to map network drives. You can do it without using the File Explorer menu, and you can even automate the process with scripts.

What happens when you map a network drive? When you map a network drive, you connect to a shared folder on another computer and assign it a drive letter (like Z:). This makes it easy to access files on that shared folder, just like you would with a local drive.

What happens when you unmap a drive? When you unmap or disconnect a drive, you break the connection between your computer and the shared folder. The drive letter will no longer be available in File Explorer.

Mapping or unmapping shared network drives using PowerShell in Windows 11 provides a convenient and efficient way to manage access to network resources. By following these steps, you can easily map network drives and access shared folders. This streamlines your workflow and enhances productivity.

Including credentials with the PowerShell command or storing them in the Credential Manager offers flexibility and security when mapping network drives. Additionally, PowerShell enables you to efficiently list and disconnect mapped network drives. This provides a comprehensive solution for managing network resources on Windows 11.

Categories:

Tags:

Leave a Reply

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