There’s multiple reasons why someone would want to mount a virtual or network drive, especially in an enterprise environment where many users don’t understand the concept of UNC paths or when older software doesn’t support long path names or UNC connections. Now there’s two things we need to know, is this a local path, or is it somewhere on the network. Once we know that we can get started.
If the folder you want to mount happens to exist on the same computer, i.e. locally we can use the subst.exe command. Let’s assume we want to mount the administrators photos to the drive letter P: we should run the following in the command prompt:
subst P: "C:\Documents and Settings\Administrator\My Documents\My Pictures"
Do not put a trailing slash at the end of Pictures, subst.exe doesn’t like it and will complain that it can’t find the path. Of course you don’t even need to run this command from the command prompt, you could run it from the Run menu. In general the command to create a virtual drive is
subst [drive1:] [drive2:]path]
where drive1 is the drive letter that you want to create and drive2:path is the file location of the folder you want to map.
Ok, so now we’v created the virtual drive and we’re ready to get rid of it. This procedure isn’t as easy as right clicking on the drive and selecting Disconnect, after all you can’t disconnect if it’s a local folder. You’re going to have to delete the virtual drive using the delete switch /d
subst P: /d
It really can’t get any simplier.
Ok, so now let’s try mapping a UNC drive with PowerShell. It’s just that simple.
$drive = $(New-Object -Com WScript.Network) $drive.MapNetworkDrive("w:", "\\ComputerName\Share")