Solved

WIndows Scripts for network resources

Posted on 2011-03-14
5
275 Views
Last Modified: 2012-05-11
Hi, I have a single active directory network encompassing 9 sites all with different IP ranges from 192.168.100.x to 192.168.180.x.  At each location there are printers and shared folders, several staff roam to the different offices frequently.  I would like to get a script that will detect where it is based on the IP range and then map the appropriate printers and shared folders accordingly to standardized drive letters.
Look forward to hearing from you gurus soon.
Cheers
Warren
0
Comment
Question by:Ozwazza
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 35134737
http://www.eggheadcafe.com/forumarchives/scriptingVisualBasicscript/Nov2005/post24366005.asp
(website offline as of posting)
suggests to check the default gateway and then base the mapping from that
code is provided
Function DefaultGateway  
  DefaultGateway = Empty  
  Dim oDG, oDGs, WMI  
  Set WMI = GetObject("winmgmts:\\.\root\cimv2")  
  Set oDGs = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")  
  For Each oDG in oDGs  
    If Not IsNull(oDG.DefaultIPGateway) Then  
      If Not oDG.defaultIPGateway(0) = "0.0.0.0" Then  
        DefaultGateway = oDG.DefaultIPGateway(0)  
        Exit For  
      End If    
    End If  
  Next  
End Function  

Select Case DefaultGateway  
  Case "10.1.1.254"  
    'Do something  
  Case "10.2.1.254"  
    'Do something  
End Select

Open in new window

0
 

Author Comment

by:Ozwazza
ID: 35175181
Can you add a bit more to the 'Do something, I would like to map printers and drives

Regards
Warren
0
 
LVL 14

Accepted Solution

by:
brendanmeyer earned 300 total points
ID: 35176787
reference
Drives
http://www.computerperformance.co.uk/Logon/logon_mapnetworkdrive_multiple.htm
Printers
http://www.computerperformance.co.uk/ezine/ezine16.htm

Dim oNetwork
Set oNetwork = CreateObject("WScript.Network") 

Function DefaultGateway  
  DefaultGateway = Empty  
  Dim oDG, oDGs, WMI  
  Set WMI = GetObject("winmgmts:\\.\root\cimv2")  
  Set oDGs = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")  
  For Each oDG in oDGs  
    If Not IsNull(oDG.DefaultIPGateway) Then  
      If Not oDG.defaultIPGateway(0) = "0.0.0.0" Then  
        DefaultGateway = oDG.DefaultIPGateway(0)  
        Exit For  
      End If    
    End If  
  Next  
End Function  

Select Case DefaultGateway  
  Case "10.1.1.254"  
    'Map Printer A
	oNetwork.AddWindowsPrinterConnection "\\server1\printera"
	'Map Drive
	objNetwork.MapNetworkDrive "U:", "\\server1\data"
  Case "10.2.1.254"  
    'Map Printer B
	oNetwork.AddWindowsPrinterConnection "\\server2\printerb"
	'Map Drive
	objNetwork.MapNetworkDrive "U:", "\\server2\data"
End Select

Set oNetwork = Nothing

Open in new window

0
 

Assisted Solution

by:Ozwazza
Ozwazza earned 0 total points
ID: 35237202
Hi, having some problems with the server mappings, it is requiring me to put in the fully qualified server name, The mapnetworkdrive is not working at all, but will look at it further.  Can I map a DFS folder using the script?

Cheers
Warren
0
 

Author Closing Comment

by:Ozwazza
ID: 35406743
Had to rework the script to include full domain name in the printer setup, also included the RemoveNetworkDrive setting otherwise would get errors if trying to remap a drive at another location
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question