Posted on 10-18-2012 08:40 AM
How can I find a mac's Active Directory name from the terminal? I've got a bunch of macs with correct AD names and incorrect local names. I want to have the correct names in Casper Inventory. I know how to change the name of the computer, but I would like to automate the process. Can anyone tell me how to get the AD name?
Thanks!
Mark
Posted on 10-18-2012 08:52 AM
dsconfigad -show | grep "Computer Account"
Posted on 10-18-2012 09:27 AM
That was exactly what I needed! Thanks!
Posted on 10-18-2012 09:27 AM
That was exactly what I needed! Thanks!
Posted on 12-07-2012 10:06 AM
How can i set this up as an Extension Attribute? So JSS can track the hostname and the preferred domain host?
dsconfigad -show | grep "Preferred Domain controller"
Posted on 12-07-2012 10:15 AM
#!/bin/sh
ADname=`dsconfigad -show | grep -i "preferred domain controller"`
echo <result>$ADname</result>
Posted on 12-07-2012 10:16 AM
Look at existing Extension Attribute templates in your JSS for how they work. The general idea is to echo back the results of what your script finds (usually in a variable) within <result> and </result> tags surrounded by quotes.
Posted on 12-07-2012 10:43 AM
This will get a cleaner result:
#!/bin/sh
PDC=`dsconfigad -show | grep -i "preferred domain controller" | sed -n 's/[^.]*= //p'`
echo <result>$PDC</result>
Posted on 12-11-2012 07:37 AM
Perfect!! This works like a charm. Thank you
Posted on 04-26-2017 02:14 PM
This will get a cleaner result for the first script to show the AD name:
#!/bin/sh
ADname=`dsconfigad -show | grep -i "Computer Account" | sed -n 's/[^.]*= // ; s/.$//p'`
/bin/echo "<result>$ADname</result>"
exit
Posted on 02-14-2018 09:11 AM
Just trying this but it cuts off the last character of the retuned domain
so my company.net shows as mycompany.ne
Any ideas?
ADname=dsconfigad -show | grep -i "Active Directory Domain" | sed -n 's/[^.]*= // ; s/.$//p'
/bin/echo "$ADname"
Posted on 02-14-2018 09:28 AM
@MatG The AD domain is something that Jamf Pro already captures natively. Is there a reason you're trying to make an Extension Attribute for this? The original post and some of the responses below it were about capturing the computer account name as it would show up inside Active Directory.
And to answer your question, it's getting cut off because of the final sed command, which is stripping off the trailing character, but that was intentional in the original script since AD computer names always have a $ at the end of them.
Posted on 02-14-2018 10:34 AM
I'm not intending to use as EA but as part of AppleScript to show domain user is on.
I thought it was the sed, but cant understand the syntax.
Posted on 02-14-2018 10:44 AM
OK, try this then:
#!/bin/bash
ADDomain=$(dsconfigad -show | awk -F'= ' '/Active Directory Domain/{print $NF}')
echo "$ADDomain"
Posted on 02-14-2018 10:48 AM
Awesome thanks.
Posted on 02-14-2018 11:25 AM
Ah, everybody has their favorite recipe for the soup.
This might tread a little more lightly than awk:
ADDomain=$(dsconfigad -show | sed -n 's/Active.Directory.Domain.*.=.//p');
echo "<result>${ADDomain}</result>"
The will tread much more heavily than other solutions, but can handle pretty much any name or encoding imaginable. It might be handy with other fields containing unusual characters.
ADDomain=$(/usr/libexec/PlistBuddy -c 'Print ":General Info:Active Directory Domain" ' /dev/stdin <<< $(dsconfigad -xml -show));
echo "<result>${ADDomain}</result>"