Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Read/Modify ADSI Attribute - GeneralizedTime

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,62094
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Read/Modify ADSI Attribute - GeneralizedTime
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Read/Modify ADSI Attribute - GeneralizedTime - 7/1/2008 9:24:58 AM   
  xybg5

 

Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
I need to update a certain user attribute in AD, we normally have to update it via ADSI editor and it takes a few min per user, and with 250+ users to update this turns into a problem. I've been looking for a way to script this and so far the best I've found is this code:

http://forums.msdn.microsoft.com/en/vbgeneral/thread/431fa29c-5471-46f9-87df-1a780fd7499e/

Originally from TechNet, it lists all attributes of the user, I used a modified version that only lists the attribute I want. However it only lists the attribute name, syntax, and value type, not the actual value. The value I need to modify lists its syntax as GeneralizedTime, how can I read then modify its value?

< Message edited by xybg5 -- 7/2/2008 9:04:59 AM >
 
 
Post #: 1
 
 RE: Read/Modify ADSI Attribute - GeneralizedTime - 7/2/2008 4:02:39 PM   
  dm_4ever


Posts: 2359
Score: 36
Joined: 6/29/2006
From: Orange County, California
Status: offline
Can you post what you've tried so far?

It may be as easy as binding to the user object and retrieving it...I won't be able to try until tomorrow.  I'd like to see what you've tried so far though.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to xybg5)
 
 
Post #: 2
 
 RE: Read/Modify ADSI Attribute - GeneralizedTime - 7/7/2008 3:05:17 AM   
  xybg5

 

Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
Sure, here ya go:

Const ForAppending = 8

Dim strLogPath, writeData

strLogPath = "c:\test\test.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Function write( writeData )
   Set objTextFile = objFSO.OpenTextFile _
       (strLogPath, ForAppending, True)
   objTextFile.WriteLine( writeData )
   objTextFile.Close
End Function



Set objUserClass = GetObject("LDAP://schema/user")
Set objSchemaClass = GetObject(objUserClass.Parent)

i = 0
writeData = "Mandatory attributes:"
write  ( writeData )
For Each strAttribute in objUserClass.MandatoryProperties
   i= i + 1
   writeData = i & vbTab & strAttribute
   write  ( writeData )
   Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
   writeData = " (Syntax: " & objAttribute.Syntax & ")"
   write  ( writeData )
   If objAttribute.MultiValued Then
       writeData = " Multivalued"
   write  ( writeData )
   Else
       writeData = " Single-valued"
   write  ( writeData )
   End If
Next

writeData =  VbCrLf & "Optional attributes:"
write  ( writeData )
For Each strAttribute in objUserClass.OptionalProperties
   i=i + 1
   writeData =  i & vbTab & strAttribute
   write  ( writeData )
   Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
   writeData =  " [Syntax: " & objAttribute.Syntax & "]"
   write  ( writeData )
   If objAttribute.MultiValued Then
       writeData =  " Multivalued"
       write  ( writeData )
   Else
       writeData =  " Single-valued"
   write  ( writeData )
   End If
Next

Lists all user attributes and prints them to a text file. Specifically the one I'm interested in shows as this:

123    iaTrainingDate
[Syntax: GeneralizedTime]
Single-valued

and if viewed through ADSI editor shows as this, the time editor box is what I get when I update it:

http://img142.imageshack.us/my.php?image=adsidt4.jpg

What I have tried is replacing the objAttribute.Syntax with objAttribute.Value. That wasn't a valid command. I've also messed with a loop to only output the attribute I wanted, that isn't in this version though.

(in reply to xybg5)
 
 
Post #: 3
 
 RE: Read/Modify ADSI Attribute - GeneralizedTime - 7/7/2008 5:24:51 AM   
  dm_4ever


Posts: 2359
Score: 36
Joined: 6/29/2006
From: Orange County, California
Status: offline
What attribute exactly are you trying to update?

Is it iaTrainingDate?  If so, this does not look like a standard property for a user account...is this a custom attribute added by you or your AD admin?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to xybg5)
 
 
Post #: 4
 
 RE: Read/Modify ADSI Attribute - GeneralizedTime - 7/7/2008 10:27:59 AM   
  xybg5

 

Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
Yes, it is a custom attribute, but its syntax is listed as GeneralizedTime or UTC Coded Time. Don't know if the syntax matters I just assumed it can be updated via script somehow. For a standard attribute, how do you update the value?

(in reply to xybg5)
 
 
Post #: 5
 
 RE: Read/Modify ADSI Attribute - GeneralizedTime - 7/7/2008 11:33:15 AM   
  dm_4ever


Posts: 2359
Score: 36
Joined: 6/29/2006
From: Orange County, California
Status: offline
Well in that case the easiest thing to try is to see if you can retrieve your accounts value....

Dim objADSysInfo : Set objADSysInfo = CreateObject("ADSystemInfo")
Dim objUser : Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WScript.Echo objUser.iaTrainingDate

If you don't want to use your account, get the distinguished name of a test account and bind to it

If you're able to see the value then you might be able to easily change it with something like

Dim objADSysInfo : Set objADSysInfo = CreateObject("ADSystemInfo")
Dim objUser : Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
objUser.iaTrainingDate = Now()
objUser.SetInfo

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to xybg5)
 
 
Post #: 6
 
 RE: Read/Modify ADSI Attribute - GeneralizedTime - 7/9/2008 3:07:56 AM   
  xybg5

 

Posts: 8
Score: 0
Joined: 1/24/2008
Status: offline
Just tried that. The Echo/SetInfo worked for standard attributes but wouldn't for this custom attribute. The Echo output a blank message box and the SetInfo gave a "General Access Denied" error. I guess that the attribute needs a different value from what Now() provides, even though the displayed format in ADSI editor is the same. Could also be some permission setting on that attribute? But I wouldn't think so as I have permission to update via ADSI editor. 

(in reply to dm_4ever)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Read/Modify ADSI Attribute - GeneralizedTime Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts