Solved

Network Script

Posted on 2012-04-11
6
352 Views
Last Modified: 2012-04-11
Hi experts

I want to make some little script when users are logging on the domain.


I want to map network driver depending on what AD Group the user is in.
Another thing, i need to set defaut printer depending on which server user is logged in...
Last thing, we got laptop and vpn connection, so the map driver should be mapped where ever the user is....

Of course I know the  .bat style scripting in /netlogon folder...
I know kixtart can do that, but is there a 2012 way to accomplish this?

Tkx
0
Comment
Question by:Burns1978
6 Comments
 
LVL 17

Expert Comment

by:Anuroopsundd
Comment Utility
you can do this with GPO ..
0
 
LVL 9

Assisted Solution

by:TazDevil1674
TazDevil1674 earned 100 total points
Comment Utility
What version of Server do you have?  If its 2008, you could use Group Policy Preferences which eliminates the required for .BAT or .KIX to run.  This is a powerful tool and once set up is much easier to maintain.

If you dont have anything at present GPP would be as time consuming as the other options.

With GPP you can configure to a particular machine/user/ip range etc so it very customisable...
0
 
LVL 7

Expert Comment

by:BelushiLomax
Comment Utility
Mapping drives and printers is very easy in Server 08 and later (assume you are on SBS)

Use Group Policy Preferences - to map drives and "Item Level Targeting" to point just to that group.
Lots of the needs for scripting have been removed from 08 with these policy preferences.

Happy to provide more complete doc if you need it...
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Expert Comment

by:Anuroopsundd
Comment Utility
0
 
LVL 17

Accepted Solution

by:
Anuroopsundd earned 400 total points
Comment Utility
0
 
LVL 6

Expert Comment

by:penguinjas
Comment Utility
The script below will map a drive based on group membership and install a printer based on the OU where the computer is located.  If applied at an OU above the computers and users in your organization it will apply anytime a user logs on and from anywhere including VPN's.

==========================================================================
'
' NAME:
'
' AUTHOR:
' DATE  :
' Revision :
'
' COMMENT: This file must be copied to all domain controllers
'
'==========================================================================
'Option explicit

On Error Resume Next
Dim WshNetwork, adsPath, strUser
Dim dso, objUser, prop
Dim strMappedDrives1, strStatus
Dim MapDrives
Dim IE, strMsg3
Dim objAdsSystemInfo, objComputerName, ObjOU, strOU
Dim CurrentDate, vbLongDate
Dim Printers      'varible for all printer objects
Dim a                  'general varible for looping drives and printers
Dim PrinterFlag, MapFlag  'variable for true, false


Const ADS_READONLY_SERVER = 4
 
Set WSHNetwork = WScript.CreateObject("WScript.Network")

'Get the User ID
                  strUser = ""
      While strUser = ""
            strUser = WSHNetwork.UserName
      Wend
      
strStatus = "Logon Script v1.0 " & Date()
      
' Call Main Routines
      
Call Print()

Call main()

'Map Default Network Drive
'This is to add a drive that everyone needs

      MapDrive "Z:", "\\Server2.contoso.local\marketing"
      

Public Sub Main()

'Main loop to detect group that user belongs To
'Where it says Contoso change it to your domain name
'This will add a drive by group membership
        
        adsPath = "WinNT://Contoso/" & strUser
        Set dso = GetObject("WinNT:")
        Set objUser = dso.OpenDSObject(adsPath,"","", ADS_READONLY_SERVER)
        For Each Prop In objUser.groups
     Select Case Prop.Name

       Case "Sales"
       Call Division1()
       
      'etc
     End Select
  Next 'Prop
      
End Sub

Sub Division1()

  'Mapped Drive for users who need access to Sales Documents folder

  MapDrive "S:", "\\Server2\Sales"
 
End Sub



Public Sub Print()

'This routine installs printers based on OU membership


      Set objAdsSystemInfo = CreateObject("adsysteminfo")
      Set objComputerName = Getobject("LDAP://" & objAdsSystemInfo.ComputerName)
      Set objOU = GetObject(objComputerName.Parent)
      strOU = replace(objOU.Name,"OU=","")
            
      Select Case strOU
            Case "Sales Computer Area"
                       Call Print1()      
 
       End Select
       
End Sub

Sub Print1()
  'Sales Printers Area  
   MapPrinter "\\Server2\Sales HP LaserJet 4"
 
 
End Sub


Function MapPrinter(name)

PrinterFlag = False

      Set Printers = WSHNetwork.EnumPrinterConnections 'Create printer objects from local host
            For a = 0 To Printers.count - 1  'Loop through all printer objects
                  'WScript.Echo Printers.item(a)      'debug line to verify looping
                  
                  If name = Printers.item(a) Then 'Check to see if printer is the one we are looking for
                        PrinterFlag = True      'if so then return true
            
            Exit For      'exit loop
                  Else
                        PrinterFlag = False
                  End if
            Next

If PrinterFlag = False Then
            WSHNetwork.AddWindowsPrinterConnection name                  
'            strStatus = strStatus & vbCRLF & "Mapped " & name
End If

      Set Printers = Nothing
      
End Function

Function MapDrive(strDrive,strShare)
      
On Error Resume Next      
      
MapFlag = false

      Set MapDrives = WshNetwork.EnumNetworkDrives  'Create MapDrive objects from local host
      
            For a = 0 To MapDrives.count - 1 Step 2 'Loop through all MapDrives objects
            'WScript.Echo MapDrives.item(a)      'debug line to verify looping
                  
                  If strDrive = MapDrives.item(a) and strShare = MapDrives.item(a+1) Then
                        MapFlag = True      'if so then return true
                        
            Exit For      'exit loop
                  End if
            Next

If MapFlag = False Then
             WSHNetwork.RemoveNetworkDrive strDrive, True, True
            WScript.Sleep 100
            WSHNetwork.MapNetworkDrive strDrive,strShare
End If

strMappedDrives1 = strMappedDrives1 & strDrive & " "

Set MapDrives = Nothing
      
End Function
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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