Solved

Network Script

Posted on 2012-04-11
6
357 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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