Link to home
Start Free TrialLog in
Avatar of FIFBA
FIFBA

asked on

VBScript to map drives based on domain name

I need a VBScript that will map 6 drives based on the domain name assigned by DHCP. I have 3 locations, 2 of them being child domains of the parent domain.
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FIFBA
FIFBA

ASKER

How can I test this without mapping drives? i.e. display the result of the domain name query. Thanks.
For seeing the domain name, use this smaller script but remember you would need to run this once in each domain to see the actual results.
Set objNetwork = CreateObject("WScript.Network")
wscript.echo = UCase(objNetwork.UserDomain)

Open in new window

Opps, please take out the "=" in line 2... it should read;
wscript.echo UCase(objNetwork.UserDomain)
Avatar of FIFBA

ASKER

I'm not quite getting the results I expected. Maybe I need to be more clear about what I'm trying to do...

I need to determine what domain name is being handed out by the dhcp server. When a user goes to different locations, I need to map drives based on the dns suffix. So even though the PC may be a member of xyz.local, I need to map drives for the domain abc.xyz.local, which would be handed out as the dns suffix by the dhcp server at abc.xyz.local.

When I run the query, I get the domain that the PC is a member of for the results, regardless of the dns suffix handed out via DHCP.

Thanks for the help so far.
Here is a short sample that will tell you the DHCP server IP address and the DNSDomain name.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set IPConfigSet = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
 
For Each IPConfig in IPConfigSet
    if IPConfig.DHCPServer <> "" then
        wscript.echo "DHCP Server:" & vbTab & IPConfig.DHCPServer & vbCRLF &_
                     "DNS Domain:" & vbTab & IPConfig.DNSDomain
    end if
Next
 
wscript.echo "Done."

Open in new window

Alternatively, does this give you the correct DNS Suffix?

Rob.
Set objShell = CreateObject("WScript.Shell")
strDNSDomain = UCase(objShell.ExpandEnvironmentStrings("%USERDNSDOMAIN%"))
WScript.Echo strDNSDomain

Open in new window

Avatar of FIFBA

ASKER

Getting closer...

When I run the first script, here's what I get...

DHCP SERVER: 192.168.200.1
DNS Domain: <empty>

then I click OK and I get

DHCP Server 192.168.1.1 (good)
DNS Domain: domain.local (good)

click OK again and get a 'done'.

So, really all I need to make this work is the DNS domain (above, domain.local is what I'm looking for).

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FIFBA

ASKER

Thanks for all the help. I think this will work. I've considered scripting based on site as you suggested but there are a couple things I would need to work out that I did not mention in my initial question. Your last script should get me most of the way there, though. Thanks again.