Extension Attribute for DSCONFIGAD check my work guys/gals!!!

Matt
Valued Contributor

Hey everyone, we are having the good ole' sharing name not matching the AD object name. I decided to put together a little EA to grab the "Computer Account" field from dsconfigad -show. In this script it capitalizes and removes the trailing $. I wanted to post my code and see if anyone can make it better or provide feedback. Currently this is working flawlessly!

#!/bin/sh

# Bound AD Object
# author: matt.lee@fox.com

adObject=`dsconfigad -show | awk '/Computer Account/{print $NF}' | tr '[a-z]' '[A-Z]' | sed s/.$//`
echo "<result>$adObject</result>"
6 REPLIES 6

ImAMacGuy
Valued Contributor II

worked perfectly on my 10.9 Box. Running it on more systems in the environment.

donmontalvo
Esteemed Contributor III

Here's ours to show if Mac is set to namespace forest or domain...

#!/bin/sh

namespace=`/usr/sbin/dsconfigad -show | grep "Namespace mode" | awk '{ print $4 }'`

echo "<result>$namespace</result>"

[EDIT: sorry, I misread your post, this will not help your cause. :( I'll leave it here so it shows up for anyone searching for dsconfigad, in case it's useful.

Don

--
https://donmontalvo.com

Matt
Valued Contributor

Thats a good one Don I am going to snag that!!!!!

Matt
Valued Contributor

Thats a good one Don I am going to snag that!!!!!

mm2270
Legendary Contributor III

The only thing I'd change Matt is the last sed command. How you have it now will remove the last character regardless of what character it is. While its unlikely. if it runs on a Mac that happens to not have a $ as its last character for the Computer Account, it would end up chopping off a valid character.

You can do this instead:

dsconfigad -show | awk '/Computer Account/{print $NF}' | tr '[a-z]' '[A-Z]' | **sed 's/$$//'**

That makes sure it only lops off that final character if its actually a "$" symbol, otherwise leave it alone.
Examples-

echo "COMPUTERNAME" | sed 's/$$//'
result:  "COMPUTERNAME"
**AND**
echo "COMPUTERNAME$" | sed 's/$$//'
result:  "COMPUTERNAME"

VS.

echo "COMPUTERNAME" | sed 's/.$//'
result:  "COMPUTERNAM"

Edit: As I mentioned, the above scenario is unlikely, but better to play it safe, especially if you plan on using the result from the EA to enforce a naming policy down the line and not just use it for reporting purposes.

estes
New Contributor III

@donmontalvo Can I modify this to "Allowed admin groups"

!/bin/sh

namespace=/usr/sbin/dsconfigad -show | grep "Namespace mode" | awk '{ print $4 }'

echo "<result>$namespace</result>"