Get AD department name

tkimpton
Valued Contributor II

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

1 ACCEPTED SOLUTION

stevewood
Honored Contributor II
Honored Contributor II

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.

View solution in original post

9 REPLIES 9

bentoms
Release Candidate Programs Tester

Hey fella,

Is that on 2 lines?

Have a look @ head & tail.

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

tkimpton
Valued Contributor II

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
Honored Contributor II
Honored Contributor II

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".

tkimpton
Valued Contributor II

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

tkimpton
Valued Contributor II

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

Anyone know how i can do this?

tkimpton
Valued Contributor II

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
Honored Contributor II
Honored Contributor II

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.

tkimpton
Valued Contributor II

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
Contributor

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