dsconfigad -show | grep "Computer Account"
That was exactly what I needed! Thanks!
That was exactly what I needed! Thanks!
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"
#!/bin/sh
ADname=`dsconfigad -show | grep -i "preferred domain controller"`
echo <result>$ADname</result>
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.
This will get a cleaner result:
#!/bin/sh
PDC=`dsconfigad -show | grep -i "preferred domain controller" | sed -n 's/[^.]*= //p'`
echo <result>$PDC</result>
Perfect!! This works like a charm. Thank you
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
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"
@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.
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.
OK, try this then:
#!/bin/bash
ADDomain=$(dsconfigad -show | awk -F'= ' '/Active Directory Domain/{print $NF}')
echo "$ADDomain"
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>"