Ext Attribute - List AD Computer Object Name

cstout
Contributor III
Contributor III

I'm curious if there is a way that I can use an extension attribute to list the name of the computer object being used for the bind to Active Directory. All I can see in my JSS currently is a bind status of "Not Bound" or the name of the domain it is bound to. Since the name of the computer (hostname for example) does not always match the computer object name, I'd like to have that listed under the Operating System tab. I would imagine this is achievable via an extension attribute script, but I'm not positive which command would be easiest and most reliable to use.

3 ACCEPTED SOLUTIONS

mm2270
Legendary Contributor III
#!/bin/sh

ADCompName=$( dsconfigad -show | awk '/Computer Account/{print $NF}' | sed 's/$$//' )

echo "<result>$ADCompName</result>"

View solution in original post

smb_samba
New Contributor III

I think something like this would work, you may need to test it out though: ```

!/bin/sh

adComputerName=dsconfigad -show | grep "Computer Account" | cut -d "=" -f2
trimmedComputerName=${adComputerName%?}
echo "<result>$trimmedComputerName</result>"
```

View solution in original post

alexjdale
Valued Contributor III

Here is what I use, I make the name uppercase for readability and consistency with other processes:

#!/bin/bash

adName=`dsconfigad -show | grep "Computer Account" | awk '{print toupper}' | awk '{print $4}' | sed 's/$$//'`

if [ ! "$adName" ]; then
adName="Not Bound"
fi

echo "<result>$adName</result>"

View solution in original post

6 REPLIES 6

smb_samba
New Contributor III

I'm not 100% sure if this is correct but this is what I used once upon a time for a similar situation:

#!/bin/sh

adComputerName=`dsconfigad -show | grep "Computer Account" | cut -d "=" -f2`

echo "<result>$adComputerName</result>"

cstout
Contributor III
Contributor III

@smb_samba, that script works wonderfully. The only problem I have with it is that it appends a "$" to the end of the name. Is that avoidable? If not, I'm totally happy with this. Thank you!

mm2270
Legendary Contributor III
#!/bin/sh

ADCompName=$( dsconfigad -show | awk '/Computer Account/{print $NF}' | sed 's/$$//' )

echo "<result>$ADCompName</result>"

smb_samba
New Contributor III

I think something like this would work, you may need to test it out though: ```

!/bin/sh

adComputerName=dsconfigad -show | grep "Computer Account" | cut -d "=" -f2
trimmedComputerName=${adComputerName%?}
echo "<result>$trimmedComputerName</result>"
```

alexjdale
Valued Contributor III

Here is what I use, I make the name uppercase for readability and consistency with other processes:

#!/bin/bash

adName=`dsconfigad -show | grep "Computer Account" | awk '{print toupper}' | awk '{print $4}' | sed 's/$$//'`

if [ ! "$adName" ]; then
adName="Not Bound"
fi

echo "<result>$adName</result>"

cstout
Contributor III
Contributor III

@smb_samba, @mm2270, and @alexjdale:

Those work great. The added benefit of having it printed to uppercase is a great extra. Thank you all for your responses!