Re: Moving user to another container
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Jul 2006 10:34:36 -0500
Hi,
The main thing is you need to bind to the user object, objUser. Also, you
should refer to objUser instead of oUser when you add the user to the group.
A less important point is that I would test if the user is already a member
of the group before adding them. A minor point is that I would bind to the
group object outside the loop, so it is bound once rather than repeatedly.
I've added to your script below:
Richard,
I guess I do need your script because I still want to use the csv file.
So I've modified your script to change the profile path and to add the
users to a security group. Would you mind checking it over please and
letting me know if the scirpt makes sense? Thanks,
==================
Option Explicit
Dim strFile, strOU, objOU, objRootDSE, strDNSDomain
Dim objTrans, strNetBIOSDomain, strNTName, strUserDN
Dim objFSO, objFile
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
' Specify the csv file. This file has one user NT name per line.
strFile = "c:\scripts\students.csv"
' Bind to group object once, outside the loop where we read names.
Set grp =
GetObject("LDAP://cn=gg047-users,dc=student,dc=cssd,dc=ab,,dc=ca")
' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""
' Use the Set method to specify the RPC 1779 format of the domain name.
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
' Use the Get method to retrieve the NetBIOS Name.
' This has a trailing backspace, which we will use.
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, 1)
' Read each line of the file and process.
Do Until objFile.AtEndOfStream
strNTName = Trim(objFile.ReadLine)
If (strNTName <> "") Then
' Use the Set method to specify the NT name.
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & strNTName
' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Change the profile attribute to the appropriate path
' These four lines were in the script center example, but I don't think I
need them?
' strCurrentProfilePath = objUser.Get("profilePath")
' intStringLen = Len(strCurrentProfilePath)
' intStringRemains = intStringLen - 11
' strRemains = Mid(strCurrentProfilePath, 12, intStringRemains)
' I agree, these lines are not needed.
' Bind to the user object, using strUserDN.
Set objUser = GetObject("LDAP://" & strUserDN)
strNewProfilePath = "\\s0470s0371-01\students2.man$"
objUser.Put "profilePath", strNewProfilePath
objUser.SetInfo
' Add users to the required 047 groups
' I'm assuming the first line I copied from the sample script is the AD
path to the security group?
' Group object bound above. I removed "Set grp" statement here.
' Add user to group only if they are not already a member.
' There is no need for the SetInfo statement.
If Not grp.IsMember(objUser.AdsPath) Then
grp.Add(objUser.AdsPath)
End If
End If
Loop
' Clean up.
objFile.Close
==================
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- Follow-Ups:
- Re: Moving user to another container
- From: ComputerTeacher
- Re: Moving user to another container
- References:
- Moving user to another container
- From: ComputerTeacher
- Re: Moving user to another container
- From: Richard Mueller
- Re: Moving user to another container
- From: ComputerTeacher
- Re: Moving user to another container
- From: ComputerTeacher
- Moving user to another container
- Prev by Date: Sites and Services config. with 12 Sites
- Next by Date: find out who has access to make changes to AD (ie. delete or create OU's
- Previous by thread: Re: Moving user to another container
- Next by thread: Re: Moving user to another container
- Index(es):
Relevant Pages
|