Jump to content

Script to write attributes to AD


Recommended Posts

Hi everyone,

I have a login script currently running that I created with autoit. I want to modify it to do another task as well, which is update the "Description" field of the computer object in AD when a user logs onto a machine. The reason being we have 1000 computers in a certain OU and theres only around 300 supposed to be there, as the other 700 are tombstoned pcs. I want to fill in the description field in AD, so after a week or two of users running this script I can delete the computer objects that do not have a description, hence cleaning up Active Directory. I want to use the user name of the person logging in to be the decription field. I currently already grab that in my login script. It is defined as $UserName. Please use this in any examples. I'm a total newb when it comes to scripting with AD. Thanks All! I appreciate it!

Nate

Link to comment
Share on other sites

  • Developers

Does the user have the proper rights to write to the AD?

Doesn't the Computer object contain a proper date for a user last changing the password while using this Computer you could retrieve from the AD?

In VBS:

lngDate = objRecordSet.Fields("pwdLastSet")

Set objDate = lngDate

dtmPwdLastSet = Integer8Date(objDate, lngBias)

Link to vbs

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Does the user have the proper rights to write to the AD?

Doesn't the Computer object contain a proper date for a user last changing the password while using this Computer you could retrieve from the AD?

In VBS:

lngDate = objRecordSet.Fields("pwdLastSet")

Set objDate = lngDate

dtmPwdLastSet = Integer8Date(objDate, lngBias)

Link to vbs

Jos

Hi,

just do a:

Your Computers are in OU MyOU in root of mydomain.namespace.local. You want to enumerate all computers of this ou, which are at least 4 weeks inactive:

dsquery computer "OU=MyOU,dc=mydomain, dc=namespace, dc=local" -inactive 4 -limit 1000

You shouldn't delete the computer accounts straight away. 1st i would set them disabled, and after a while i would delete them. You can make a combination of dsquery and dsmod:

dsquery computer "ou=MyOU,dc=mydomain, dc=namespace, dc=local" -inactive 4 -limit 1000 | dsmod computer -disabled yes

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

To find out when the last logon of a computer to the domain happend just query the lastLogon attribute. You can use the adfunctions UDF which can be found here. You have to convert the returned value to readable format using this script.

Edited by water

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