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

x
?
Solved

Network Script

Posted on 2012-04-11
6
Medium Priority
?
364 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
ID: 37832964
you can do this with GPO ..
0
 
LVL 9

Assisted Solution

by:TazDevil1674
TazDevil1674 earned 400 total points
ID: 37832969
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
ID: 37832977
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37832986
0
 
LVL 17

Accepted Solution

by:
Anuroopsundd earned 1600 total points
ID: 37832994
0
 
LVL 6

Expert Comment

by:penguinjas
ID: 37833095
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

885 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