#HOW TO MAP A MAC NETWORK DRIVE IN WINDOWS SERVER 2012 R2 KEYGEN#
![how to map a mac network drive in windows server 2012 r2 how to map a mac network drive in windows server 2012 r2](https://itssc.rpi.edu/hc/article_attachments/360050146012/mceclip1.png)
(Step 1, the default value for a For Next loop, hits every item.) Setting the Step value to 2 ensures that we’ll pass only drive letters to the RemoveNetworkDrive method. That’s what the Step 2 does it tells VBScript to only hit every other item. On top of that, we also need to skip every other item instead of hitting items 0, 1, 2, 3, 4, 5, we want to hit only items 0, 2, and 4 (the items that contain drive letters). If you have 100 items in the collection the last item will have an index number of 99, or 100-1.) Because the first item is item 0, the last item will always be the total number of items minus 1 in this case, 3-1, or 2.
![how to map a mac network drive in windows server 2012 r2 how to map a mac network drive in windows server 2012 r2](https://i.ytimg.com/vi/iGRqTbsMWZ0/maxresdefault.jpg)
![how to map a mac network drive in windows server 2012 r2 how to map a mac network drive in windows server 2012 r2](https://i.ytimg.com/vi/PoCOu8d23jI/mqdefault.jpg)
(Why “minus 1? Well, in a three-item collection item numbers would be 0, 1, and 2. To that end, we use a For Next loop, looping from 0 (the first item in a collection is always item 0) to the number of drives in the collection minus 1. Which also means we need to figure out a way around this issue. Which, of course, means that you’re script is going to fail. That’s not so good: there aren’t going to be any drives with a drive letter \\atl-fs-01-share1.
![how to map a mac network drive in windows server 2012 r2 how to map a mac network drive in windows server 2012 r2](https://i.stack.imgur.com/Xr100.png)
However, the second time through the loop we’d pass RemoveNetworkDrive the value \\atl-fs-01-share1. If we looped through all the items in the collection, the first time through the loop we’d pass RemoveNetworkDrive the value X. In order to remove a network drive, we need to call the RemoveNetworkDrive method, passing the method the drive letter for the drive to be removed. That’s why we can’t use a simple For Each loop to loop through the items in the collection. Each of the other drives also has two items in the collection, meaning our three mapped drives will result in a six-item collection, with items alternating between drive letter and UNC path. One drive, but two entries in the mapped network drive collection. The second item in the collection (item 1) is the UNC path to the shared folder on drive X: \\atl-fs-01\share1. The first item in the collection (item 0) is the drive letter for drive X: X. The collection returned by EnumNetworkDrives will look something like this: X:Īs you can see, each mapped drive actually has two entries in the collection. Suppose you have three mapped drives on your computer (drives X, Y, and Z). This is where the quirkiness of WSH’s mapped network drives collection manifests itself. First, though, let’s point out that the script starts off by creating an instance of the Wscript.Network object we then call the EnumNetworkDrives method to return a collection of all the mapped network drives on a computer. Yes, this is odd-looking code, but we’ll explain why it looks that way. ObjNetwork.RemoveNetworkDrive colDrives.Item(i) Set colDrives = objNetwork.EnumNetworkDrives Set objNetwork = CreateObject(“Wscript.Network”) So how do you remove all the mapped network drives on a computer? Here’s one way: On Error Resume Next That can be a bit inconvenient, to say the least (there’s no straightforward way to run a script that unmaps drives on a remote machine), but in this case it doesn’t matter that’s because logon scripts always run locally anyway. WSH does the job just fine, but with one caveat: WSH can map and unmap drives only on the local computer. Why? Well, one of the drawbacks to mapping and unmapping network drives is the fact that there are no WMI classes capable of performing these tasks that means we have to rely on Windows Script Host to remove mapped network drives. You know, we’re glad you specifically mentioned the term “logon script” in your question. ** For more details about mapping drives on a Mac, see Connecting to Network Storage on a Mac.Hey, Scripting Guy! How can I use a logon script to remove all mapped drives each time a user logs on? If you are unsure of what either path should be, contact the TTS Service Desk at or call (617) 627-3376. Q: or R: drive syntax = \\ server\ departmental-sever\ your_department P: drive syntax = \\\ your_tufts_username Therefore, the best practice is to always use \\ ( smb:// on a Mac) when mapping your Tufts network drives. The use of \\titan\xxxxxxxx will work when physically on the Tufts network, but you must use the fully qualified domain name of \\\xxxxxxxx when connecting from a remote location.