Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WIndows Scripts for network resources

Posted on 2011-03-14
5
Medium Priority
?
283 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 1200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Let's recap what we learned from yesterday's Skyport Systems webinar.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

916 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