Skip to main content
Question

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

  • August 6, 2013
  • 6 replies
  • 16 views

Forum|alt.badge.img+20
  • Valued Contributor
  • 732 replies

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

ImAMacGuy
Forum|alt.badge.img+23
  • Esteemed Contributor
  • 1310 replies
  • August 6, 2013

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


donmontalvo
Forum|alt.badge.img+36
  • Hall of Fame
  • 4293 replies
  • August 6, 2013

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


Forum|alt.badge.img+20
  • Author
  • Valued Contributor
  • 732 replies
  • August 7, 2013

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


Forum|alt.badge.img+20
  • Author
  • Valued Contributor
  • 732 replies
  • August 7, 2013

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


mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • August 7, 2013

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.


Forum|alt.badge.img+4
  • Contributor
  • 22 replies
  • April 5, 2017

@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>"