Skip to main content
Solved

macOS & Active Directory // How to append text to description field with bash?


Forum|alt.badge.img+2

Good morning.

My institution is moving forward with migrating among domains. I came across this idea to see if I could take all existing Macs from our existing domain, and upon re-binding them to the new one, append text to the description field with a Shell Script. I'm unable to move the existing objects, I must re-bind.

I already have configuration profiles in place, but if anyone has any idea with how I can reference the description fields, any help would be appreciated.

Effectively, I'm looking for what was already done in this PowerShell article:

http://woshub.com/how-automatically-fill-computer-description-field-in-active-directory/

Best answer by signetmac

You'd have to figure out what the dscl path is in your own environment. Here's mine:

ELV_ACCT=    # your Active Directory elevated account name here
PASS=        # may I recommend this workflow here: https://github.com/jamfit/Encrypted-Script-Parameters
DOMAIN=      # your domain here
COMPUTER=    # name of the computer you whose record you are altering
DESCRIPTION= # text you want to put in the Description field

dscl -u $ELV_ACCT -P $PASS "/Active Directory/$DOMAIN/All Domains/" -append /Computers/${COMPUTER}$ Comment "$DESCRIPTION"

Note: this won't work if you already have a description in the field. Obviously this isn't an issue if you've just bound the computer in the same script, but If the description on the record of an already existing computer is immaterial, then precede it with a delete of the Comment attrib:

dscl -u $ELV_ACCT -P $PASS "/Active Directory/$DOMAIN/All Domains/" -delete /Computers/${COMPUTER}$ Comment
View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+2
  • Author
  • New Contributor
  • 1 reply
  • June 27, 2018

So far, I've figured out the command(s) which successfully append and delete descriptions [comments] from an active directory object:

dscl -u <AD username with permissions here> "/Active Directory/<Domain>/<subDomain>" -append /Computers/<RecordName> Comment <Insert Description here>

dscl -u <AD username with permissions here> "/Active Directory/<Domain>/<subDomain>" -delete /Computers/<RecordName> Comment

My next question would be: Is it possible to run this script without having to manually insert credentials?


Forum|alt.badge.img+10
  • Contributor
  • 40 replies
  • Answer
  • June 27, 2018

You'd have to figure out what the dscl path is in your own environment. Here's mine:

ELV_ACCT=    # your Active Directory elevated account name here
PASS=        # may I recommend this workflow here: https://github.com/jamfit/Encrypted-Script-Parameters
DOMAIN=      # your domain here
COMPUTER=    # name of the computer you whose record you are altering
DESCRIPTION= # text you want to put in the Description field

dscl -u $ELV_ACCT -P $PASS "/Active Directory/$DOMAIN/All Domains/" -append /Computers/${COMPUTER}$ Comment "$DESCRIPTION"

Note: this won't work if you already have a description in the field. Obviously this isn't an issue if you've just bound the computer in the same script, but If the description on the record of an already existing computer is immaterial, then precede it with a delete of the Comment attrib:

dscl -u $ELV_ACCT -P $PASS "/Active Directory/$DOMAIN/All Domains/" -delete /Computers/${COMPUTER}$ Comment

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings