Re: Changing User Profile

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 02/20/04


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
> >--
> >
> >
> >.
> >


Relevant Pages

  • Re: Report in FM 6 or 7
    ... achieve this report format will have to be done via scripting. ... but they will simplify the script and Sort Order. ... End Loop ... The normal 'Dancer' field is used so that if there are more than one ...
    (comp.databases.filemaker)
  • Re: recreate database script not work
    ... I got a script which is supposed to regenerate database systax. ... REM gen_dbse_9.sql ... end loop; ...
    (comp.databases.oracle.server)
  • Re: Loop Problem (At Least I think)
    ... If there are no images matching the product ... "" Then" statement (the one below the loop, outside of it), is this just ... >> script to finish. ... > 2) Read the database table and acess the dictionary object for the ...
    (microsoft.public.scripting.vbscript)
  • Re: How to set up a global variable in a sub-routine?
    ... the 'global variables' are more like constants ... ... single script, I need a way to tell it only once where the file is and ... So, if you construct a loop with a loop variable, you ... >programmers avoid global variables completely. ...
    (perl.beginners)
  • RE: (Urgent) Create many txt files from tables with DTS Package
    ... when i run this script the error show: ... > How to loop through a global variable Rowset ... >> D.90.70.0002 Husain Djojonegoro BOARD OF COMMISSIONER ... >> D.50.04.0071 Putu Supertama Checker BI ...
    (microsoft.public.sqlserver.dts)