Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jiwaldorf

macrumors newbie
Original poster
Dec 28, 2016
5
0
Where is the Active Directory Computer ID stored when you bind the computer to active directory?



I want to use something similar to /usr/sbin/scutil --get ComputerName | /usr/sbin/scutil --set HostName $1

to set the computername, localhostname and host name as the active directory computer id.



I'm aware of the below commands but none of those match the active directory id

scutil --get ComputerName

scutil --get LocalHostName

scutil --get HostName
 
The two main commands I know of for Directory Services are 'dscl' and 'dsconfigad'. Read their man pages for details.

This should show some AD info. The name you want may be in there:
Code:
dsconfigad -show

The list of all DS commands should be the output from this command line:
Code:
ls -l /usr/*bin/ds*

I have nothing available here that uses AD, so I can't tell you any more than that.
 
The two main commands I know of for Directory Services are 'dscl' and 'dsconfigad'. Read their man pages for details.

This should show some AD info. The name you want may be in there:
Code:
dsconfigad -show

The list of all DS commands should be the output from this command line:
Code:
ls -l /usr/*bin/ds*

I have nothing available here that uses AD, so I can't tell you any more than that.

Thank you. I started using the dsconfigad command to add computers. I'll play with this.
[doublepost=1483042724][/doublepost]
Thank you. I started using the dsconfigad command to add computers. I'll play with this.

Your post got me able to google the right thing.

#!/bin/sh ADCompNametemp=`dsconfigad -show | grep "Computer Account" | sed 's/Computer Account//' | sed 's/=//'` ADCompNametemp2=${ADCompNametemp//[[:space:]]/} ADCompName=${ADCompNametemp2%?} scutil --set HostName "$ADCompName" scutil --set LocalHostName "$ADCompName" scutil --set ComputerName "$ADCompName"

The only thing I need now is to switch it from lower case to capital.

Thank you and Happy New Year!
 
Example:
Code:
echo lower case and Mixed Case | tr '[a-z]' '[A-Z]'

Sorry to bother. I've tried putting this string on every line but it's not getting me the result I want.
When the command is complete it echoes the result in all caps.
What I want is for it to physically change the computer name, local host name and host name from lower case to capital.

What am I doing wrong?
 
Sorry to bother. I've tried putting this string on every line but it's not getting me the result I want.
When the command is complete it echoes the result in all caps.
What I want is for it to physically change the computer name, local host name and host name from lower case to capital.

What am I doing wrong?
You posted a fairly involved command-line in post #3 without any additional info, so I thought you knew what you were doing and just needed to know the command (tr) and the translation mappings, i.e. an example.

First, you said you found the right thing, so please post the URL of what you found. I'd like to read the original, partly because what you posted is all run together on a single line in post #3.

Second, if what you posted in post #3 actually consists of multiple lines, please repost it as multiple lines. Use the "More Options..." button below your post-editing box to Preview your post, to ensure that it will appear correctly. Use CODE tags around the multiple command lines.

I can tell you what to change, but only if I know exactly what you're working with.
 
You posted a fairly involved command-line in post #3 without any additional info, so I thought you knew what you were doing and just needed to know the command (tr) and the translation mappings, i.e. an example.

First, you said you found the right thing, so please post the URL of what you found. I'd like to read the original, partly because what you posted is all run together on a single line in post #3.

Second, if what you posted in post #3 actually consists of multiple lines, please repost it as multiple lines. Use the "More Options..." button below your post-editing box to Preview your post, to ensure that it will appear correctly. Use CODE tags around the multiple command lines.

I can tell you what to change, but only if I know exactly what you're working with.

I was hoping to figure it out myself. I'm learning as I go. I am signed up to start taking classes this month on programming. I appreciate your help.

What I had found was from Experts Exchange.
https://www.experts-exchange.com/qu...ript-command-to-get-the-AD-computer-name.html

Code:
#!/bin/sh
ADCompNametemp=`dsconfigad -show | grep "Computer Account" | sed 's/Computer Account//' | sed 's/=//'`
ADCompNametemp2=${ADCompNametemp//[[:space:]]/}
ADCompName=${ADCompNametemp2%?}
scutil --set HostName "$ADCompName"
scutil --set LocalHostName "$ADCompName"
scutil --set ComputerName "$ADCompName"

This accomplished what I want however it does it in lower case. I need it to do it in capitals.
I run this in Apple Remote Desktop.
 
Last edited:
I was hoping to figure it out myself. I'm learning as I go. I am signed up to start taking classes this month on programming. I appreciate your help.

What I had found was from Experts Exchange.
https://www.experts-exchange.com/qu...ript-command-to-get-the-AD-computer-name.html

Code:
#!/bin/sh
ADCompNametemp=`dsconfigad -show | grep "Computer Account" | sed 's/Computer Account//' | sed 's/=//'`
ADCompNametemp2=${ADCompNametemp//[[:space:]]/}
ADCompName=${ADCompNametemp2%?}
scutil --set HostName "$ADCompName"
scutil --set LocalHostName "$ADCompName"
scutil --set ComputerName "$ADCompName"

This accomplished what I want however it does it in lower case. I need it to do it in capitals.
I run this in Apple Remote Desktop.
Try this:

Code:
#!/bin/sh
ADCompNametemp=`dsconfigad -show | grep "Computer Account" | sed 's/Computer Account//' | sed 's/=//'`
ADCompNametemp2=${ADCompNametemp//[[:space:]]/}
ADCompName=${ADCompNametemp2%?}

ADCompName="$(echo "$ADCompName" | tr '[:lower:]' '[:upper:]')"

scutil --set HostName "$ADCompName"
scutil --set LocalHostName "$ADCompName"
scutil --set ComputerName "$ADCompName"
 
That's exactly what I needed. I was missing the "ADCompName="$(echo "$ADCompName" |" part.

Thank you so much!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.