Solved

Network Script

Posted on 2012-04-11
6
356 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
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.

856 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