Re: Enumerating organisational units within vbs script
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 5 Dec 2007 08:16:31 -0600
TJ wrote:
I have developed alot of vbs logon scripts and administrate a medium
size network, we are just about to make certain users have "roaming
profiles", i have created the script below to read a list of account
names and set there profile path to do so the only problem is i have
to hardcode the organisational unit which the user is in, what i would
like to do is enumerate all containers so regardless of what ou the
user sits in it will update the profile.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("roamingprofiles.txt", ForReading)
Do Until objTextFile.AtEndOfStream
AccountName = objTextFile.ReadLine
Set objUser = GetObject _
("LDAP://CN=" & AccountName & ",OU=staff,DC=my domain,DC=com")
objUser.Put "profilePath", "\\storage\profiles\" & accountName
wscript.echo "profile set for " & accountName & " to \\server\share\"
& accountName
objUser.SetInfo
Loop
' end of script
Any help would be greatly appreciated.
There are two approaches. One is a recursive function to enumerate OU's,
similar to:
==========
Dim objDomain
' Bind to domain object.
Set objDomain = GetObject(LDAP://dc=MyDomain,dc=com)
Call EnumOUs(objDomain)
Sub EnumOUs(objParent)
' Recursive sub to enumerate OU's.
Dim objUser, objChild
' First, enumerate users in the Parent.
objParent.Filter = Array("user")
For Each objUser In objParent
' Do something with each user.
objUser.Put "profilePath", \\storage\profiles\ _
& objUser.sAMAccountName
objUser.SetInfo
Next
' Filter on child OU's and containers.
objParent.Filter = Array("organizationalUnit", "container")
' Enumerate child OU's.
For Each objChild In objParent
' Call this sub recursively.
Call EnumOUs(objChild)
Next
End Sub
=========
The sAMAccountName attribute is the "pre-Windows 2000 logon name", which is
probably what you mean by account name.
Another approach is to use ADO to retrieve information on all users in the
domain. See this link for details:
http://www.rlmueller.net/ADOSearchTips.htm
However ADO cannot be used to modify attributes directly, so you must
retrieve the distinguishedNames of the users and use this bind to the user
object to make changes.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- Enumerating organisational units within vbs script
- From: TJ_2006
- Enumerating organisational units within vbs script
- Prev by Date: Re: System Volume Information Access Denied and filling up
- Next by Date: Trial Software downloads
- Previous by thread: Enumerating organisational units within vbs script
- Next by thread: Re: Setup site to site VPN?
- Index(es):
Relevant Pages
|