Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Must I move the AD Groups I've created to the Default location so my script can see them, or is there another way...?

Reply
Thread Tools Display Modes

Must I move the AD Groups I've created to the Default location so my script can see them, or is there another way...?

 
 
Kelvin
Guest
Posts: n/a

 
      08-20-2009
I've been playing with a logon script and have a need different need to
check so was playing with this code.

The script seems to check this Default loccation:
domain.local\Users

But not where I've been storing the Groups I've created
domain.local\City\Groups

Do I need to move my Groups to the default location or can I have it also
check the location I've created?

Maybe there's a much better way to do this all together...

Any input would be appreciated

Kelvin

This is the code I was using to check Group membership:
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
' Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain

'----------------------------8<----------------------------
' Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
Call MsgBox("WinDir is " & WinDir)

'----------------------------8<----------------------------
' Grab the user name
UserString = WSHNetwork.UserName
Call MsgBox("Users name is " & UserString)

'----------------------------8<----------------------------
' Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
Call MsgBox("Computer name is " & strComputer)

'----------------------------8<----------------------------
' Bind to the user object to get user name and check for group memberships
later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'----------------------------8<----------------------------
'Check naming convention for mapping of the P: drive

'----------------------------8<----------------------------
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case
sensitive.
Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
'Note the use of all upper case letters as mentioned above.
'Note also that the groups must be Global Groups.

Case "LEASINGSTAFF"
Call MsgBox("Member of LEASINGSTAFF " & GroupObj.Name)

Case "ADMINISTRATION"
Call MsgBox("Member of ADMINISTRATION " & GroupObj.Name)

Case "PARTSSTAFF"
Call MsgBox("Member of PARTSSTAFF " & GroupObj.Name)

Case "SALES"
Call MsgBox("Member of SALES " & GroupObj.Name)

Case "SERVICE"
Call MsgBox("Member of SERVICE " & GroupObj.Name)

Case "BUSINESSOFFICESTAFF"
Call MsgBox("Member of BUSINESSOFFICESTAFF " & GroupObj.Name)

Case "DOMAIN USERS"
Call MsgBox("Member of DOMAIN USERS " & GroupObj.Name)

Case "DOMAIN ADMINS"
Call MsgBox("Member of DOMAIN ADMINS " & GroupObj.Name)

End Select

Next


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      08-20-2009
Kelvin wrote:

> I've been playing with a logon script and have a need different need to
> check so was playing with this code.
>
> The script seems to check this Default loccation:
> domain.local\Users
>
> But not where I've been storing the Groups I've created
> domain.local\City\Groups
>
> Do I need to move my Groups to the default location or can I have it also
> check the location I've created?
>
> Maybe there's a much better way to do this all together...
>
> Any input would be appreciated
>
> Kelvin
>
> This is the code I was using to check Group membership:
> ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
> Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
> Path
>
> Set WSHShell = CreateObject("WScript.Shell")
> Set WSHNetwork = CreateObject("WScript.Network")
> ' Automatically grab the user's domain name
> DomainString = Wshnetwork.UserDomain
>
> '----------------------------8<----------------------------
> ' Find the Windows Directory
> WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
> Call MsgBox("WinDir is " & WinDir)
>
> '----------------------------8<----------------------------
> ' Grab the user name
> UserString = WSHNetwork.UserName
> Call MsgBox("Users name is " & UserString)
>
> '----------------------------8<----------------------------
> ' Grab the computer name for use in add-on code later
> strComputer = WSHNetwork.ComputerName
> Call MsgBox("Computer name is " & strComputer)
>
> '----------------------------8<----------------------------
> ' Bind to the user object to get user name and check for group memberships
> later
> Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
>
> '----------------------------8<----------------------------
> 'Check naming convention for mapping of the P: drive
>
> '----------------------------8<----------------------------
> 'Now check for group memberships and map appropriate drives
> 'Note that this checks Global Groups and not domain local groups.
> For Each GroupObj In UserObj.Groups
> 'Force upper case comparison of the group names, otherwise this is case
> sensitive.
> Select Case UCase(GroupObj.Name)
> 'Check for group memberships and take needed action
> 'In this example below, ADMIN and WORKERB are groups.
> 'Note the use of all upper case letters as mentioned above.
> 'Note also that the groups must be Global Groups.
>
> Case "LEASINGSTAFF"
> Call MsgBox("Member of LEASINGSTAFF " & GroupObj.Name)
>
> Case "ADMINISTRATION"
> Call MsgBox("Member of ADMINISTRATION " & GroupObj.Name)
>
> Case "PARTSSTAFF"
> Call MsgBox("Member of PARTSSTAFF " & GroupObj.Name)
>
> Case "SALES"
> Call MsgBox("Member of SALES " & GroupObj.Name)
>
> Case "SERVICE"
> Call MsgBox("Member of SERVICE " & GroupObj.Name)
>
> Case "BUSINESSOFFICESTAFF"
> Call MsgBox("Member of BUSINESSOFFICESTAFF " & GroupObj.Name)
>
> Case "DOMAIN USERS"
> Call MsgBox("Member of DOMAIN USERS " & GroupObj.Name)
>
> Case "DOMAIN ADMINS"
> Call MsgBox("Member of DOMAIN ADMINS " & GroupObj.Name)
>
> End Select
>
> Next


There are better ways, but after a quick glance at your script I think it
should work. There should be no need to move your groups.

You are using the WinNT provider, which is slower and reveals fewer
attributes. It sees Active Directory as a flat namespace. It is blind to
OU's, but still sees all user, group, and computer objects no matter where
they are in AD, as long as you use "pre-Windows 2000" names. The wshNetwork
object retrieves "pre-Windows 2000" names.

I would test your script, not as a logon script, but at a command prompt
after logon. I would have the script echo all groups the user is a member
of. For example, a test script could be:
=============
Set WSHShell = CreateObject("WScript.Shell")
DomainString = Wshnetwork.UserDomain
UserString = WSHNetwork.UserName

Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
Wscript.Echo "Current user: " & UserObj.Name

Wscript.Echo "User belongs to groups"
For Each GroupObj In UserObj.Groups
Wscript.Echo GroupObj.Name
Next
=========
The only conditions I can think of where this could fail in a logon script,
is if the client OS is older than Windows 2000. If your script runs after
logon, but seems to fail as a logon script, then perhaps you OS is Windows
95/98. Reply if this is the case, as there is a workaround.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Must I move the AD Groups I've created to the Default location so my script can see them, or is there another way...? Kelvin Active Directory 1 08-20-2009 05:24 PM
RE: Should I move my exchange store from it's default location or leave it where it is? Terence Liu [MSFT] Windows Small Business Server 0 11-26-2007 08:21 AM
Re: Should I move my exchange store from it's default location or leave it where it is? Lanwench [MVP - Exchange] Windows Small Business Server 0 11-20-2007 07:28 PM
how to move location of default database???? plz! trehug Windows Media Player 15 03-01-2007 05:27 AM
RE: Default Users/My User location, is it possible to move the default to D:/ drive? William Topping Windows Vista General Discussion 2 10-08-2006 05:45 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59