forked from jamf/Jamf-Nation-Extension-Attributes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathActive Directory OU.xml
27 lines (27 loc) · 942 Bytes
/
Active Directory OU.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="UTF-8"?>
<extensionAttribute>
<displayName>Active Directory OU</displayName>
<description>If the computer is bound to Active Directory it will show the path to where it is located in AD. Helpful for Smart Groups based on objects in a particular OU. </description>
<dataType>string</dataType>
<scriptContentsMac>#!/bin/sh
ad_computer_name=`dsconfigad -show | grep "Computer Account" | awk '{print $4}'`
ad_computer_ou=`dscl /Search read /Computers/$ad_computer_name | \
grep -A 1 dsAttrTypeNative:distinguishedName | \
cut -d, -f2- | sed -n 's/OU\=//gp' | \
sed -n 's/\(.*\),DC\=/\1./gp' | \
sed -n 's/DC\=//gp' | \
awk -F, '{
N = NF
while ( N > 1 )
{
printf "%s/",$N
N--
}
printf "%s",$1
}'`
echo "<result>$ad_computer_ou</result>"
</scriptContentsMac>
<scriptContentsWindows/>
</extensionAttribute>