Solved

WIndows Scripts for network resources

Posted on 2011-03-14
5
273 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

Join & Write a Comment

I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now