Solved

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

Posted on 2008-10-01
5
416 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
  • 3
  • 2
5 Comments
 

Author Comment

by:excelsupport
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now