# Roaming user login script needs to map drives...



## axis77 (Aug 31, 2004)

I have a user that moves from different locations every week, so for example he can be at area A with ServerA, then area B with ServerB
What im looking for is a way to run his login script that would know if he was at area A or Area B and mapped that specific servers folder share...
ex. current script
map network drive n: \\serverA\share

but if he was in Area B today his script still says 
map network drive n: \\ServerA\share

How do I make a roaming script that knows if hes at AreaA or AreaB???
map network drive n: \\%Servername%\share

Any Ideas?


----------



## TheOutcaste (Aug 8, 2007)

Assuming each location has been configured into a different Active Directory site, use *gpresult* (*gpresult /R* for Vista/Win 7) or a VBScript to get the Site name, then use that to read the appropriate server name from a list of sites

```
For /F "Tokens=3 Delims=: " %%I In ('gpresult ^|Findstr /I /C:"Site Name:"') Do Set _SiteName=%%I 
For /F "Tokens=2 Delims=:" %%I In ('Type Serverlist.txt^|Findstr /I "%_SiteName%"' ) Do Set _Servername=%%I
```
*Serverlist.txt* should be in the same folder as the logon script, or the path should be specified, andbe setup like this, using the correct site and server names:

Site1:ServerA
Site2:ServerB
Site3:ServerC

Example:
Building05:WarehouseServerA

This VBScript should be faster than waiting for the entire gpresult output to be generated.
Save the following as *FindSite.vbs*:

```
Set objADSysInfo = CreateObject("ADSystemInfo")
WScript.Echo "Site Name: " & objADSysInfo.SiteName
```
Then use this to get the site name

```
For /F "Tokens=3 Delims=: " %%I In ('cscript //nologo FindSite.vbs') Do Set _SiteName=%%I
For /F "Tokens=2 Delims=:" %%I In ('Type Serverlist.txt^|Findstr /I /C:"%_SiteName%"' ) Do Set _Servername=%%I
```
If you haven't set up sites, you'll need to find something you can read that is unique to each location, such as an IP address (Default Gateway, DNS, DHCP, WINS).
If the sites are not connected, you can use the *logonserver* variable, however, if a logon server isn't available, and the system logs on using cached credentials, the *logonserver* variable will contain the name of the last server that processed the credentials, which could be for a different site.


----------

