Solved

WIndows Scripts for network resources

Posted on 2011-03-14
5
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 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