How to delete the old network drive and add new one with one command in cmd?

Szymon Rabiza 101 Reputation points
2021-06-21T05:44:55.777+00:00

Hello,
How could I delete the old network drive and add the new with one command in cmd, is this even possible ?

Best Regards

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
11,930 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,261 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Laude 85,591 Reputation points
    2021-06-21T06:17:20.03+00:00

    Hi @Szymon Rabiza ,

    To add and delete a network drive with cmd you can make use of the net use commands.

    net use z: /delete && net use z: \\servername\share

    ----------

    If the reply was helpful please don't forget to upvote and/or accept as answer, thank you!

    Best regards,
    Leon

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. BosunDoug 6 Reputation points
    2021-06-27T06:51:07.287+00:00

    Hello, @Szymon Rabiza and all.
    Further to the archived thread at <https://social.technet.microsoft.com/Forums/en-US/f4460a73-6a42-47f8-950b-2f18e03c0a7e/impossible-to-remove-a-persistent-network-drive-mapping-when-logged-on-disconnected?forum=win10itprogeneral> and the above answers; you may wish to use the following commands.

    Net Use z: /Delete
    Mountvol z: /d
    if not exist z:\ (Net Use z: \servername\share /Persistent:YES)

    These three lines can be concatenated into a single command line expression, by using ampersands (&).

    I have struggled for the last six months and have developed an elaborate batch file to remap my home network drives on my laptop; as Windows 10 doesn't always find them again. Today, the referenced archived thread pointed me to using both Net Use /d and Mountvol /d — as a pair. Kudos to @Giacomo and @Grajon, as the net use and mountvol pair obviates the need to stop and restart file Explorer; which itself introduces other (potential) issues!

    Best regards,
    BosunDoug

    PS. Per the original/archived thread, I too suspect this is an unresolved Windows 10 bug.

    1 person found this answer helpful.
    0 comments No comments

  2. Jiang Zhang 786 Reputation points
    2021-06-21T07:47:14.813+00:00

    Hi,
    You may refer to LeonLaude’s answer: net use z: /delete && net use z: \servername\share.

    Best Regards,
    Mulder Zhang

    --------------------------------------------------------------

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments