Skip to main content
Solved

Get AD department name

  • October 14, 2013
  • 9 replies
  • 31 views

Forum|alt.badge.img+21

Hi guys

im trying to get my AD deparment.

So when i do

dscl /Active Directory/RUFUS_DOMAIN/All Domains/ -read /Users/tkimpton

i want to be able to get my department

dsAttrTypeNative:department: Information Systems

Problem is im having problem outputting just Information Systems.

Can anyone help me?

Thanks

Best answer by stevewood

I just tried this and received the proper info back:

tell application "Finder"

set Department to do shell script "dscl /Active\\ Directory/INTEGERDALLAS/All\\ Domains/ -read /Users/swood dsAttrTypeNative:department | grep -oi 'information systems'"

display dialog Department

end tell

The trick for me were the double back slashes and then the single quote in the grep statement.

9 replies

bentoms
Forum|alt.badge.img+35
  • Hall of Fame
  • October 14, 2013

Hey fella,

Is that on 2 lines?

Have a look @ head & tail.

Something like that. Is this fot populating AD info innthe Jss?


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • October 14, 2013

had a bit of a blank lol

this worked

dscl /Active Directory/RUFUS_DOMAIN/All Domains/ -read /Users/tkimpton department | tr -d '
' | awk '{$1 =""; print }' | sed '1s/^.//'

stevewood
Forum|alt.badge.img+38
  • Hall of Fame
  • October 14, 2013

Not the prettiest way to do it, but grep might work as well. A quick test of this worked for me:

dscl /Active Directory/INTEGERDALLAS/All Domains/ -read /Users/swood dsAttrTypeNative:department | grep -oi "information systems"

That returned "Information Systems" for my user, and when I tried a user that had a different department, it returned blank. For users that had no department it returned "No such key: dsAttrTypeNative:department".


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • October 14, 2013

Hi Ben

yeah its on the second line. I know theres lots of ways of doing things and eventually thought of it.

Its there an easier way with head and tail?

would be easier to remember lol


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • October 14, 2013

bit of a problem trying to get my original command in an Applescript :(

Anyone know how i can do this?


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • October 14, 2013

Brilliant Steve. Im trying to get this in an applescript and having problems with it though. I have tried

set Department to do shell script "dscl /Active Directory/RUFUS_DOMAIN/All Domains/ -read /Users/tkimpton dsAttrTypeNative:department | grep -oi "Information Systems"

stevewood
Forum|alt.badge.img+38
  • Hall of Fame
  • Answer
  • October 14, 2013

I just tried this and received the proper info back:

tell application "Finder"

set Department to do shell script "dscl /Active\\ Directory/INTEGERDALLAS/All\\ Domains/ -read /Users/swood dsAttrTypeNative:department | grep -oi 'information systems'"

display dialog Department

end tell

The trick for me were the double back slashes and then the single quote in the grep statement.


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • October 14, 2013

Thanks Steve much appreciated, you brought me back from the brinks of madness

This is what is used for the applescript in the end

set loggedInUser to do shell script "whoami"

set ISDepartment to do shell script "dscl /Active\\ Directory/RUFUS_DOMAIN/All\\ Domains/ -read /Users/" & loggedInUser & " dsAttrTypeNative:department | grep -oi 'Information Systems'"

mani2care
Forum|alt.badge.img+7
  • Contributor
  • November 29, 2020

hi do we have any updated script to update AD user full name department email id and more to update to inventory via extension attribute or policy can help