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

Szymon Rabiza 101 Reputation points

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.
12,086 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,266 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Laude 85,651 Reputation points

    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,

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. BosunDoug 6 Reputation points

    Hello, @Szymon Rabiza and all.
    Further to the archived thread at <> 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,

    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

    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