Re: Changing User Profile
From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 02/20/04
- Next message: Richard Mueller [MVP]: "Re: Check default printer"
- Previous message: Michael Harris \(MVP\): "Re: Check default printer"
- In reply to: Richard: "Re: Changing User Profile"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Feb 2004 19:30:32 -0600
Hi,
Since your "For Each" loop enumerated all objects in the OU, the loop
included the group objects. Groups do not have a homeDirectory attribute, so
an error would be raised when you attempted to assign a value. However, you
said the loop completed, so the script did not stop, possibly because you
used "On Error Resume Next". If no error was raised and the loop completed,
I would expect all user objects to be modified, even if the group objects
were not.
To restrict the "For Each" loop to just user objects, the normal practice is
to use the Filter method. For example:
Set ou = GetObject(....
ou.Filter = Array("user")
For Each oUser in ou
...
However, computer objects would also be included, since they inherit from
the user class (that's why they have a homeDirectory attribute, even though
it doesn't make sense). To really restrict the loop to user objects you
would have to use the Class property method:
Set ou = GetObject(....
ou.Filter = Array("user")
For Each oUser in ou
If LCase(oUser.Class) = "user" Then
oUser.Put "homeDirectory", ....
oUser.SetInfo
End If
Next
The objectClass attribute is multi-valued. For user objects, objectClass
equals top, person, organizationalPerson, and user. for Computers,
objectClass equals top, person, organizationalPerson, user, and computer.
For groups, objectClass equals top and group. The Filter method includes all
objects where any item in the objectClass collection matches. However, the
Class property method is a bit smarter and returns a single value equal to
the "most significant" class that contributes properties to the object (my
terminology, since I can't really define it - maybe it's the last class in
the collection).
I'm glad the script worked, although I'm not sure I can explain fully.
-- Richard Microsoft MVP Scripting and ADSI HilltopLab web site - http://www.rlmueller.net -- "Richard" <anonymous@discussions.microsoft.com> wrote in message news:12c9001c3f748$d113af20$a301280a@phx.gbl... > Thanks for the reply. You said something that struck me, > only user accounts, I had two groups in the OU, I removed > them and it worked. Is that why? > >-----Original Message----- > >Mark wrote: > > > >> I have just migrated all my users home folders to a new > >> Windows 2003 server using robocopy and it worked great. > >> Now I need to change the home directory path in the > users > >> profile tab within AD Users and Computers. I am trying > >> to run the following script, but it will not change the > >> path... > >> > >> Set ou = GetObject > >> ("LDAP://OU=ausers,OU=Admin,DC=domain,DC=com") > >> for each oUser in oU > >> ' wscript.echo(ouser.name) > >> oUser.Put "homeDirectory", "\\domain.com\admin_use > >> rs\" & oUser.samAccountName > >> oUser.SetInfo > >> > >> Next > >> Wscript.echo "Users modified!" > >> > >> > >> Can anyone tell me why? It seems to run through the > >> script as I get the Users modified message, but again, > >> path does not change. > > > >Hi, > > > >I don't see the problem. If you have "On Error Resume > Next", remove this or > >comment it out to see which line raises an error. Other > than the line > >wrapping, the code looks OK to me (assuming there are > only user objects in > >the OU - otherwise, you should filter). > > > >-- > >Richard > >Microsoft MVP Scripting and ADSI > >HilltopLab web site - http://www.rlmueller.net > >-- > > > > > >. > >
- Next message: Richard Mueller [MVP]: "Re: Check default printer"
- Previous message: Michael Harris \(MVP\): "Re: Check default printer"
- In reply to: Richard: "Re: Changing User Profile"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|