Sign in to follow this  
Followers 0
hazed

ACtive Directory Modify description

8 posts in this topic

I am trying to add a description after I add a Computer to Active Directory.

I used the following code to query the Descriptions, but Now I need to Update them.

I tried adding $objectList.Update but that didn't work.

$computerName = "DP2CCB1"

$filterStr = "(&(objectclass=computer))"

$ado = ObjCreate("ADODB.Connection")

$ado.Provider = "ADSDSOObject"

$ado.Properties("User ID") = "xxxx"

$ado.Properties("Password") = "yyyyy"

$ado.Properties("Encrypt Password") = 1

$ado.Open ("ADS-Search" )

$adoCmd = ObjCreate("ADODB.Command")

$adoCmd.ActiveConnection = $ado

;$adoCmd.Properties("Page Size") = 99

;$adoCmd.Properties("Cache Results") = 1

;$adoCmd.CommandText = "<LDAP://" & $serverName & "/" & $baseStr & ">;" & $filterStr & ";ADsPath;subtree"

$adoCmd.CommandText = "<LDAP://Cn="&$computername&", OU=Laptops,DC=xxxx,DC=Com>;" & $filterStr & ";ADsPath;subtree"

$objectList = $adoCmd.Execute

While Not $objectList.EOF()

$user = ObjGet($objectList.Fields("ADsPath").value)

ConsoleWrite ($user.Name &" "&$user.description& @CRLF)

$objectList.MoveNext

Wend

Share this post


Link to post
Share on other sites



I am trying to add a description after I add a Computer to Active Directory.

I used the following code to query the Descriptions, but Now I need to Update them.

I tried adding $objectList.Update but that didn't work.

$computerName = "DP2CCB1"

$filterStr = "(&(objectclass=computer))"

$ado = ObjCreate("ADODB.Connection")

$ado.Provider = "ADSDSOObject"

$ado.Properties("User ID") = "xxxx"

$ado.Properties("Password") = "yyyyy"

$ado.Properties("Encrypt Password") = 1

$ado.Open ("ADS-Search" )

$adoCmd = ObjCreate("ADODB.Command")

$adoCmd.ActiveConnection = $ado

;$adoCmd.Properties("Page Size") = 99

;$adoCmd.Properties("Cache Results") = 1

;$adoCmd.CommandText = "<LDAP://" & $serverName & "/" & $baseStr & ">;" & $filterStr & ";ADsPath;subtree"

$adoCmd.CommandText = "<LDAP://Cn="&$computername&", OU=Laptops,DC=xxxx,DC=Com>;" & $filterStr & ";ADsPath;subtree"

$objectList = $adoCmd.Execute

While Not $objectList.EOF()

$user = ObjGet($objectList.Fields("ADsPath").value)

ConsoleWrite ($user.Name &" "&$user.description& @CRLF)

$objectList.MoveNext

Wend

$user.Description = "new description"
$user.SetInfo

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

$user.Description = "new description"
$user.SetInfo

This failed, I thought I did this earlier, but I tried again

C:\Documents and Settings\hazed\Desktop\machine descriptions.au3 (26) : ==> The requested action with this object has failed.:

$user.SetInfo

$user.SetInfo^ ERROR

Share this post


Link to post
Share on other sites

This failed, I thought I did this earlier, but I tried again

C:\Documents and Settings\hazed\Desktop\machine descriptions.au3 (26) : ==> The requested action with this object has failed.:

$user.SetInfo

$user.SetInfo^ ERROR

Does the account you are running the program under have appropriate rights to modify the account description you are testing with?

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites

try:

$User.Put ("Description", "Test User description")
$User.SetInfo

:)

This didn't work either, and I do have access. I am wondering if ADO can modify Active Directory. One website I found, mentioned something to that effect.

Which makes sense to me.

Share this post


Link to post
Share on other sites

#include <AD.au3>

_AD_Open()

_AD_ModifyAttribute("John Doe", "Description", "Lost in time")

_AD_Close()

Share this post


Link to post
Share on other sites

A bit late - the thread is 3 1/2 years old - but glad you use my UDF :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0