Sometimes there are instances in which you need to map drives on specific servers and not all. One of the ways to accomplish this is through the use of startup scripts defined in local policy. For this need I just needed a server to map to another server resource, the G:\ drive in particular.
Applies To: Windows 7, Windows Server 2008 R2
Create the cmd script to contain the net use command to connect. In this example I am clearing anything on G, waiting 5 seconds and then connecting to my server using domain user id and password. I am saving the file in a directory I use for scripts, c:\support\scripts and calling it mapg.cmd.
net use g: /delete sleep 5 net use g: \\myserver\g$ /user:domain\userid "password"
Now to assign computer startup scripts
Open the Local Group Policy Editor. (Run > mmc > File > Add or Remove Snap-ins > Select Group Policy Object Editor. Click OK to accept Local Policy and click OK.)
In the console tree, click Scripts (Startup/Shutdown). The path is Computer Configuration\Windows Settings\Scripts (Startup/Shutdown).
In the results pane, double-click Startup.
In the Startup Properties dialog box, click Add.
In the Add a Script dialog box, do the following:
- In the Script Name box, type the path to the script, or click Browse to search for the script file in the Netlogon shared folder on the domain controller.
- In the Script Parameters box, type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called //logo (display banner) and //I (interactive mode), type //logo //I.
In the Startup Properties dialog box, specify the options that you want:
- Startup Scripts for <Group Policy object>: Lists all the scripts that currently are assigned to the selected Group Policy object (GPO). If you assign multiple scripts, the scripts are processed in the order that you specify. To move a script up in the list, click it and then click Up. To move a script down in the list, click it and then click Down.
- Add: Opens the Add a Script dialog box, where you can specify any additional scripts to use.
- Edit: Opens the Edit Script dialog box, where you can modify script information, such as name and parameters.
- Remove: Removes the selected script from the Startup Scripts list.
- Show Files: Displays the script files that are stored in the selected GPO
Right click on Startup and select Properties, click Add and click browse and navigate to the script containing the net use command you would like to use.
Click OK to save the changes and reboot the server to test the drive mapping.
Fairly simple to implement and you can expand on the use in other areas. For my part it resolved an issue I tasked it for and was easy to implement.