Solved

Login script not getting domain group name after updating Active Directory schema

Posted on 2008-10-01
5
423 Views
Last Modified: 2012-06-22
I recently updated a Windows Server 2000 Domain Controller schema to allow a Server 2003 Domain Controller to join the domain.

Since then the login scripts that I have inherited have stopped working correctly. The script maps drives and printers based on group membership and sometimes on user names.

I think I have tracked it down to the code that is pulling the group names and user names from Active Directory.

Perhaps someone can tell me what needs to be changed (If I am on the right track) to get the details from the new AD Schema?
Set objLocalGroup = GetObject("WinNT://" & strComputerName & "/" & strLocalGroup & ",group")
Set objDomainGroup = GetObject("WinNT://" & strNetBIOSDomain & "/" & strDomainGroup & ",group")
Set objUserGroup = GetObject("WinNT://" & strNetBIOSDomain & "/" & strUserName)

Open in new window

0
Comment
Question by:excelsupport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:excelsupport
ID: 22613430
This bit of the script might be helpful...
strDomainGroup = "Domain Users"
strNetBIOSDomain = WshNetwork.UserDomain
strUserName = WshNetwork.UserName
strLocalGroup = "Administrators"
strComputerName = WshNetwork.ComputerName

Open in new window

0
 
LVL 33

Expert Comment

by:MikeKane
ID: 22614009
We would need to know what is not working on the script to trouble shoot it.   And it would help to post the script so we could have a look at the entire code.
0
 

Author Comment

by:excelsupport
ID: 22614634
I didn't post the whole script as I would rather not publicise our network environment. So to that end I have genericised the script so don't get too hung up on the names. Also some variables may not be used as the script has been modified over the years and never rewritten from scratch.

As for what isn't working, again, it isn't mapping drives or printers based on group name.

I tried echoing the group name variable but nothing happens.

I know enough VB to modify what is already there but know very little about AD scripting or what I can pull back and how...

I updated the Win2k AD Schema to enable a Win2k3 Server AD to join the domain and now the mapping by group name isn't working, which lead me to think the code to get the group names from AD is maybe out of date for the scripting/get object methods?
'------------------------Declare variables----------------------------------------------------
'
Dim WshNetwork, wshShell, WSHPrinters
Dim objLocalGroup, objDomainGroup, objWMIService, objPrinter, objUserGroup
Dim strComputerName, strDomainGroup, strNetBIOSDomain, strUserName, strComputer, PrinterPath, PrinterDriver, strLocalGroup
Dim colInstalledPrinters, clDrives, i, GroupObj, LOOP_COUNTER
'
'=============================================================================================
 
'------------------ Additions to retain user selected default printer-------------------------
Dim objNetwork, currDefPrn
Set objNetwork = CreateObject("WScript.Network") 
'------------------ Get the current default printer-------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set defPrinter = objWMIService.ExecQuery("Select name from Win32_Printer where(Default=true)")
for each obj in defPrinter
'wscript.echo " Current Default printer  = " & obj.name
currDefPrn = obj.name
next
' current default printer stored in currDefPrn now
'=============================================================================================
 
Set WshNetwork = CreateObject("WScript.Network")
Set wshShell = WScript.CreateObject ("WSCript.shell")
On Error Resume Next
 
'---------------Add To Power Users Group------------------------------------------------------
 
strComputerName = WshNetwork.ComputerName
Select Case UCase(strComputerName)
Case "DOMAIN CONTROLLER 1"
On Error Resume Next
'Do not add Domain Users to local administrators account on this computer as that would make all users Administrators
Case "DOMAIN CONTROLLER 2"
On Error Resume Next
'Do not add Domain Users to local administrators account on this computer as that would make all users Administrators
Case Default
On Error Resume Next
strDomainGroup = "Domain Users"
strNetBIOSDomain = WshNetwork.UserDomain
strUserName = WshNetwork.UserName
strLocalGroup = "Administrators"
Set objLocalGroup = GetObject("WinNT://" & strComputerName & "/" & strLocalGroup & ",group")
Set objDomainGroup = GetObject("WinNT://" & strNetBIOSDomain & "/" & strDomainGroup & ",group")
Set objUserGroup = GetObject("WinNT://" & strNetBIOSDomain & "/" & strUserName)
On Error Resume Next
wscript.sleep(1000)
objLocalGroup.Add(objDomainGroup.ADsPath)
On Error GoTo 0
End Select
 
 
'===========================================================================================
 
 
'-------Delete All Networked Printers-------------------------------------------
On Error Resume Next
Set WSHPrinters = WshNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
	'On Error Resume Next
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
      WshNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
    End If
Next
 
'================================================================================
 
'---------All Computer Map These Printers------------------------------
 
	'On Error Resume Next
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER1"
PrinterDriver = "PRINTER1 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER2"
PrinterDriver = "PRINTER2 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER3"
PrinterDriver = "PRINTER3 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER4"
PrinterDriver = "PRINTER4 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER5"
PrinterDriver = "PRINTER5 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER6"
PrinterDriver = "PRINTER6 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER7"
PrinterDriver = "PRINTER7 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER8"
PrinterDriver = "PRINTER8 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER9"
PrinterDriver = "PRINTER9 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
'=======================================================================
 
'-------------Selected Printing-----------------------------------------
 
'-------------For Computer Name-----------------------------------------
 
'Select Case UCase(strComputerName)
'Case "GROUP1"
'On Error Resume Next
'PrinterPath = "\\DOMAIN CONTROLLER\PRINTER1"
'PrinterDriver = "PRINTER1"
'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
'Case "GROUP2"
'On Error Resume Next
'PrinterPath = "\\DOMAIN CONTROLLER\PRINTER2"
'PrinterDriver = "PRINTER2"
'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
'End Select
 
'------------For Group Name----------------------------------------------
 
For Each GroupObj In objUserGroup.Groups
wscript.echo " Current User Group  = " & GroupObj.Name
Select Case GroupObj.Name
'
Case "OFFICE1"
On Error Resume Next
WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER3"
'
Case "OFFICE2"
On Error Resume Next
WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER4"
'
Case "OFFICE3"
On Error Resume Next
WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER5"
'
Case "OFFICE4"
On Error Resume Next
'WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER6"
WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER7"
'
Case "OFFICE5"
On Error Resume Next
WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER8"
'
Case "OFFICE6"
On Error Resume Next
PrinterPath = "\\DOMAIN CONTROLLER\PRINTER9"
PrinterDriver = "PRINTER9 DRIVER NAME"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
 
'
Case "OFFICE7"
On Error Resume Next
WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER9"
'
 
End Select
Next
 
'------------For User Name--------------------------------------------
'
'These remain as examples - the default case is to assign users to groups and assign the printers to the groups
'
'Select Case UCase(strUserName)
'Case "AUSER"
'On Error Resume Next
'PrinterPath = "\\DOMAIN CONTROLLER\PRINTER1"
'PrinterDriver = "PRINTER1 DRIVER NAME"
 
'Case "ANOTHERUSER"
'On Error Resume Next
'PrinterPath = "\\DOMAIN CONTROLLER\PRINTER1"
'PrinterDriver = "PRINTER1 DRIVER NAME"
'WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
'WshNetwork.SetDefaultPrinter "\\DOMAIN CONTROLLER\PRINTER1"
 
'End Select
 
'===============================================================
 
'-------Restore user selected default printer------------------------------
 
' Set the default printer back to user selected default
objNetwork.SetDefaultPrinter currDefPrn
 
'--------------------------------------------------------------------------
 
 
'-------Delete All Mapped Drives-------------------------------------------
 
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
 
'============================================================================
 
'-------Mapped Network Drives For All--------------------------------------
 
On Error Resume Next
'
'WshNetwork.MapNetworkDrive "x:", "\\DOMAIN CONTROLLER\data1",True
WshNetwork.MapNetworkDrive "y:", "\\DOMAIN CONTROLLER\data2",True
WshNetwork.MapNetworkDrive "z:", "\\DOMAIN CONTROLLER\data3",True
WshNetwork.MapNetworkDrive "w:", "\\DOMAIN CONTROLLER\data4",True
 
 
'===========================================================================
 
'-------Selected Mapped Network Drives-------------------------------------
 
Select Case UCase(strUserName)
'Case "A USER"
'On Error Resume Next
'WshNetwork.MapNetworkDrive "R:", "\\DOMAIN CONTROLLER\z$",True
'WshNetwork.MapNetworkDrive "Y:", "\\DOMAIN CONTROLLER\z$",True
'WshNetwork.MapNetworkDrive "K:", "\\DOMAIN CONTROLLER\data5",True
 
 
Case "ANOTHER USER"
 
wscript.echo "Sleeping for 10 secs near start of driver case script"
wscript.sleep(10000)
'Erase all mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
 
'On Error Resume Next
'WshNetwork.MapNetworkDrive "x:", "\\DOMAIN CONTROLLER\data6",True
 
'
'
End Select
 
'============================================================================
 
'------Mapped Drives For Group Membership-----------------------------------
 
For Each GroupObj In objUserGroup.Groups
Select Case GroupObj.Name
	Case "GROUP 1"
On Error Resume Next
      WshNetwork.MapNetworkDrive "u:", "\\DOMAIN CONTROLLER\data6",True
   Case "GROUP 2"
On Error Resume Next   
	WshNetwork.MapNetworkDrive "t:", "\\DOMAIN CONTROLLER\data7",True 
	'WshNetwork.MapNetworkDrive "r:", "\\DOMAIN CONTROLLER\data8",True 
	WshNetwork.MapNetworkDrive "o:", "\\DOMAIN CONTROLLER\data9",True 
	'WshNetwork.MapNetworkDrive "p:", "\\DOMAIN CONTROLLER\data10",True 
	WshNetwork.MapNetworkDrive "p:", "\\DOMAIN CONTROLLER\data11",True 
	WshNetwork.MapNetworkDrive "r:", "\\DOMAIN CONTROLLER\data12",True 
	WshNetwork.MapNetworkDrive "q:", "\\DOMAIN CONTROLLER\data13",True 
	 
 
End Select
Next
 
'===========================================================================
 
 
 
'-----Clean Up--------------------------------------------------------------------
 
Set objLocalGroup = Nothing
Set objDomainGroup = Nothing
Set objWMIService = Nothing
Set objPrinter = Nothing
Set strComputer = Nothing
Set strUserName = Nothing
Set strNetBIOSDomain = Nothing
Set strDomainGroup = Nothing
Set strComputerName = Nothing
Set PrinterPath = Nothing
Set PrinterDriver = Nothing
Set objUserGroup = Nothing
Set clDrives = Nothing
Set i = Nothing
Set GroupObj = Nothing
Set wshShell = Nothing
Set WSHPrinters = Nothing
Set LOOP_COUNTER = Nothing
 
'================================================================================

Open in new window

0
 
LVL 33

Accepted Solution

by:
MikeKane earned 500 total points
ID: 22616124
This is a snippet of code I always use.   It will run a test against a group name (see the snippet window)

If you include this code in your script, you can issue calls to the script using something like the following:

If IsMemberOf("GROUP 1") Then
    WshNetwork.MapNetworkDrive "u:", "\\DOMAIN CONTROLLER\data6",True
End If


This code works on 2003 domains, I use it on mine.....  





Function IsMemberOf(sGroupName) 
Set oNetwork = CreateObject("WScript.Network") 
sDomain = oNetwork.UserDomain 
sUser = oNetwork.UserName 
bIsMember = False 
Set oUser = GetObject("WinNT://" & sDomain & "/" & _ 
sUser & ",user") 
For Each oGroup In oUser.Groups 
If oGroup.Name = sGroupName Then 
bIsMember = True 
Exit For 
End If 
Next 
IsMemberOf = bIsMember 
End Function 

Open in new window

0
 

Author Comment

by:excelsupport
ID: 22623671
Looking at your function, the only difference I can see in how you get the user groups is in the GetObject line...

"WinNT://" & sDomain & "/" & sUser & ",user"

vs

"WinNT://" & strNetBIOSDomain & "/" & strUserName"

The only difference here is that you are appending ",user" to the end... could that be the problem?

==========

I have now tried your script and it works as expected, so I added the ",user" bit on and things started to work. I also discovered another error in the Select Case in the "Case Default" should be "Case Else"

It all seems to be working.

Your code wasn't a direct answer to why my script wasn't working but helped me find the error, so thanks for that.

Will try and test it today...
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

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

This article runs through the process of deploying a single EXE application selectively to a group of user.
In-place Upgrading Dirsync to Azure AD Connect
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 …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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