brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: net use maps a network share to a drive letter from the Windows command line

Windows
~/tips/tip-windows-net-use-map-drive

net use Z: \\server\share * /user:name /persistent:yes

Maps an SMB share to a drive letter, asks for the password, and removes the mapping again.

Windows has a perfectly good dialog for mapping a network drive, but I find it slow to click through. net use does the same in one line, and it also tells you what is currently connected.

net use Z: \\server\share * /user:name /persistent:yes

This assigns the drive letter Z: to the share. The * in the password position makes Windows ask for the password, and the password is not shown while you type it. That keeps it out of your command history. With /user: you connect as a different user, and Domain\User is allowed. Put an asterisk instead of a drive letter and Windows picks the next free one.

The documentation says /persistent:yes saves the connection and restores it at the next logon, and /persistent:no does not. The default is whatever you used last, which is easy to forget. Run net use alone to list your connections, or net use Z: for one of them.

To remove one mapping:

net use Z: /delete

Caveats. net use * /delete cancels all network connections at once, so use it with care. You cannot disconnect a share that is your current drive or that a running process is using. A server name with spaces needs quotation marks. /savecred stores the credentials for reuse, which is convenient on a private PC and a bad idea on a shared one.

Further reading: Net use (Microsoft Learn, archived Windows Server reference)

Going deeper: Guide: your Unraid cache is full and Docker stopped, how to find out why and fix it

More Windows tips Win+Ctrl+C Win+Shift+Left arrow Win+Ctrl+Left arrow Alt+PrtScn Left Alt + Left Shift + Print Screen All Windows tips (35) All topics

Link