Jump to content

ACtive Directory Modify description


Recommended Posts

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

Link to comment
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
Link to comment
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

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • 3 years later...

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...