Solved

Network Script

Posted on 2012-04-11
6
355 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 100 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37832986
0
 
LVL 17

Accepted Solution

by:
Anuroopsundd earned 400 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
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 …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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