Where is the Active Directory Computer ID stored when you bind the computer to active directory?

Discussion in 'Mac Programming' started by jiwaldorf, Dec 28, 2016.

  1. jiwaldorf macrumors newbie

    Joined:
    Dec 28, 2016
    #1
    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
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. jiwaldorf thread starter macrumors newbie

    Joined:
    Dec 28, 2016
    #3
    Thank you. I started using the dsconfigad command to add computers. I'll play with this.
    --- Post Merged, Dec 29, 2016 ---
    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!
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Example:
    Code:
    echo lower case and Mixed Case | tr '[a-z]' '[A-Z]'
     
  5. jiwaldorf thread starter macrumors newbie

    Joined:
    Dec 28, 2016
    #5
    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?
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    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.
     
  7. jiwaldorf, Jan 3, 2017
    Last edited: Jan 3, 2017

    jiwaldorf thread starter macrumors newbie

    Joined:
    Dec 28, 2016
    #7
    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.
     
  8. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #8
    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"
     
  9. jiwaldorf thread starter macrumors newbie

    Joined:
    Dec 28, 2016
    #9
    That's exactly what I needed. I was missing the "ADCompName="$(echo "$ADCompName" |" part.

    Thank you so much!
     

Share This Page