Syntax error How to map the network drive using PowerShell?

How to map the network drive using PowerShell?



You can map the network drive on the local and remote computers using several ways.

  • Using cmd command.

You can use the below command to map the network drive, here letter M, and the shared folder on the local computer.

Example

net use M: "\remoteshare\Shared Folder"

PS C:\WINDOWS\system32> net use M:
Local name        M:
Remote name       \remoteshare\Shared Folder
Resource type     Disk
Status            OK
# Opens           1
# Connections     1
The command completed successfully.

To map on the remote computer.

Invoke-Command -ComputerName RemoteComputer -ScriptBlock{net use k: "\remoteshare\shared"}
  • Using the New-PSDrive command.

You can map a network drive using Powershell command New-PSDrive on local and remote computers both.

To map a drive on the local computer.

New-PSDrive -Name K -PSProvider FileSystem -Root \remoteshare\shared -Persist

Output

PS C:\WINDOWS\system32> Get-PSDrive -Name K

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
K                 318.16         47.24 FileSystem    \remoteshare\shared

To map a drive on the remote computer.

Invoke-Command -ComputerName Remotecomputer -ScriptBlock {New-PSDrive -Name K -PSProvider FileSystem -Root \remoteshare\shared -Persist}
Updated on: 2020-11-11T12:11:35+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements