How to get active directory domain name on Mac via terminal

Basically, I try to get through the terminal terminal's username: username@full.name.of.activedomain.com on Windows, I can run "whoami / upn" and it will print everything. or nothing if the user is not in Active Directory. so whoami for windows works like a charm to me. On Mac, I found a command called HOSTNAME. and there is also an alias - $ HOSTNAME. if the end user is tied to Active Directory - will he display his name? in other words - I could then call this command: echo $ USER @ $ HOSTNAME to get the user principal name ...

or maybe some other command or an alias that I can use in the terminal? please, help.

+1
active-directory macos
source share
2 answers

The script part can help you find upn on OSX:

domainName=`echo show com.apple.opendirectoryd.ActiveDirectory | scutil | grep DomainNameFlat | awk '{print $3}'` if [ $? -ne 0 ] then echo "Failed to get domain name, exiting script" exit 1 fi if [ -z $domainName ] then echo "Failed to get domain name, exiting script" exit 1 fi echo "AD Domain name: $domainName " userName=`id -u -nr` if [ $? -ne 0 ] then echo "Failed to get user name, exiting script" exit 1 fi echo "User name: $userName" upn=`dscl "/Active Directory/$domainName/All Domains" -read /Users/$userName userPrincipalName` if [ $? -ne 0 ] then echo "Failed to get user upn, exiting script" exit 1 fi 
0
source share

The above value is a BASH script. Ideally, the first line requires seating. I have not tested the above script, but dscl is a directory command line utility.

! / usr / bin / env bash

-2
source share

All Articles