Skip to main content
Solved

Intune Extension Attribute

  • August 26, 2019
  • 29 replies
  • 212 views

Forum|alt.badge.img+8

Just wondering if anyone has come up with an extension attribute for Intune integration. Looking to use a smart group to keep track of devices (or users) not yet enrolled in intune.

Best answer by ThijsX

Hi,

See below my EA, it will get the Azure ID from the current logged in user and report it back to Jamf Pro.
You can set a smart group to show all none and mark that as not-registered

#!/bin/bash


loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

AADUNIQUEID="$(grep UniqueId /Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortal.usercontext.info | awk -F""" '{print $2}')"

if [[ "${AADUNIQUEID}" == "" ]] ; 
then
    /bin/echo "<result>None</result>"
else
    /bin/echo "<result>${AADUNIQUEID}</result>"
fi

exit 0

29 replies

Forum|alt.badge.img+9
  • New Contributor
  • August 26, 2019

What version of Jamf Pro are you running? Recent versions have added a couple InTune/AAD related things that can be used to report. I haven't found a need to use an EA anymore like I used to.


Forum|alt.badge.img+18
  • Contributor
  • August 26, 2019

I'm also looking for this. At least in 10.12, while there is an Azure AD ID you can pull as a data point for a registered Mac, you cannot use that as a criteria for group membership.


ThijsX
Forum|alt.badge.img+20
  • Employee
  • Answer
  • August 27, 2019

Hi,

See below my EA, it will get the Azure ID from the current logged in user and report it back to Jamf Pro.
You can set a smart group to show all none and mark that as not-registered

#!/bin/bash


loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

AADUNIQUEID="$(grep UniqueId /Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortal.usercontext.info | awk -F""" '{print $2}')"

if [[ "${AADUNIQUEID}" == "" ]] ; 
then
    /bin/echo "<result>None</result>"
else
    /bin/echo "<result>${AADUNIQUEID}</result>"
fi

exit 0

Forum|alt.badge.img+8
  • Author
  • Contributor
  • September 10, 2019

Thanks Thijs! Thats exactly what I needed to get this deployed.


Forum|alt.badge.img+4
  • Contributor
  • May 18, 2020

Hi @txhaflaire , sounds like it doesn't work with recent version of Intune Client, could you assist please ? Thank you in advance,


ThijsX
Forum|alt.badge.img+20
  • Employee
  • May 18, 2020

@JamelB Please explain? it still works in our env. Jamf Pro collects this value out of the box at the moment though!


Forum|alt.badge.img+4
  • Contributor
  • May 18, 2020

Thank you @txhaflaire When I run the command locally, you can see the behaviour in the screenshot attached. The AADUNIQUEID is empty even if it exists in the xml file.

https://ibb.co/mDfbQtD


ThijsX
Forum|alt.badge.img+20
  • Employee
  • May 18, 2020

@JamelB does the $loggedInUser get populated correctly on the device?


Forum|alt.badge.img+4
  • Contributor
  • May 18, 2020

@txhaflaire Yes it is

https://ibb.co/3p66pr3


Forum|alt.badge.img+4
  • Contributor
  • May 25, 2020

@txhaflaire any chance to assist ? Thank you


Forum|alt.badge.img+11
  • Valued Contributor
  • June 6, 2020

This stopped working for me as well. I was able to modify the EA to use PlistBuddy instead of grep.

#!/bin/bash

loggedInUser=$( /usr/bin/who | /usr/bin/awk '/console/{ print $1 }' )

AADUNIQUEID="$(/usr/libexec/PlistBuddy -c Print /Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortal.usercontext.info | grep aadUniqueId | cut -d '=' -f2 | xargs)"

if [[ "${AADUNIQUEID}" == "" ]] ;
then
    /bin/echo "<result>None</result>"
else
    /bin/echo "<result>${AADUNIQUEID}</result>"
fi

exit 0

Forum|alt.badge.img+8
  • Contributor
  • June 15, 2020

Daniel's EA worked for me. The built-in Azure AD values don't seem consistent, especially between the different views inside Jamf Pro.

This is consistent enough for a Smart Group


Forum|alt.badge.img+4
  • Contributor
  • June 19, 2020

@daniel.behan awesome, it works perfectly, thank you very much :)


Forum|alt.badge.img+8
  • Contributor
  • April 9, 2021

If anyone's looking at this in 2021; the name of the Company Portal .info file has changed to

com.microsoft.CompanyPortalMac.usercontext.info

Note the additional "Mac" in the filename.
Modify that in Daniel's script and you are good to go !


Forum|alt.badge.img+3
  • New Contributor
  • June 3, 2021

Wondering if this is still working for everyone? I just tried in Jamf 10.29.2 with Intune Company Portal 2.14 installed and it does not appear to be working.


Forum|alt.badge.img+4
  • Contributor
  • June 14, 2021

@matt.vin I just set this up today. This grep script worked for me when I changed the name of the file as mentioned above. The other script I found out there using awk didn't work for me today. I had never used either prior.


Forum|alt.badge.img+7
  • Valued Contributor
  • June 16, 2021

Hey everyone. Thank you all for keeping this thread going it's been a great help to me. I, unfortunately, didn't have much luck with the first script, and had some success with Daniel's script after updating the .plist name with the 'Mac' value. When I ran Daniel's script with the updated 'Mac' name value it would return a UUID-looking string.

I inspected the com.microsoft.CompanyPortalMac.usercontext.info file and observed the 'aadUniqueID' is a UUID value while the 'aadUserID' value is the UPN of the account signed in with Intune. I just modified Daniel's script replacing the 'aadUniqueID' entries with 'aadUserID' and it spits out the UPN just fine.

I hope this helps.

Company Portal 2.16.210501

#!/bin/sh

loggedInUser=$( /usr/bin/who | /usr/bin/awk '/console/{ print $1 }' )

AADUSERID="$(/usr/libexec/PlistBuddy -c Print /Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info | grep aadUserId | cut -d '=' -f2 | xargs)"

if [[ "${AADUSERID}" == "" ]] ;
then
    /bin/echo "<result>None</result>"
else
    /bin/echo "<result>${AADUSERID}</result>"
fi

exit 0

Forum|alt.badge.img+8
  • Contributor
  • December 30, 2021

Hey everyone. Thank you all for keeping this thread going it's been a great help to me. I, unfortunately, didn't have much luck with the first script, and had some success with Daniel's script after updating the .plist name with the 'Mac' value. When I ran Daniel's script with the updated 'Mac' name value it would return a UUID-looking string.

I inspected the com.microsoft.CompanyPortalMac.usercontext.info file and observed the 'aadUniqueID' is a UUID value while the 'aadUserID' value is the UPN of the account signed in with Intune. I just modified Daniel's script replacing the 'aadUniqueID' entries with 'aadUserID' and it spits out the UPN just fine.

I hope this helps.

Company Portal 2.16.210501

#!/bin/sh

loggedInUser=$( /usr/bin/who | /usr/bin/awk '/console/{ print $1 }' )

AADUSERID="$(/usr/libexec/PlistBuddy -c Print /Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info | grep aadUserId | cut -d '=' -f2 | xargs)"

if [[ "${AADUSERID}" == "" ]] ;
then
    /bin/echo "<result>None</result>"
else
    /bin/echo "<result>${AADUSERID}</result>"
fi

exit 0

I tried your script as well and the result is none even though I enrolled it in intune

any idea?

 


Forum|alt.badge.img+8
  • Contributor
  • January 6, 2022

I tried your script as well and the result is none even though I enrolled it in intune

any idea?

 


Can you manually check that the devices has a AAUserID exists ? Does Jamf list it in "Local Accounts" on a device inventory ?


Forum|alt.badge.img+8
  • Contributor
  • January 6, 2022

Can you manually check that the devices has a AAUserID exists ? Does Jamf list it in "Local Accounts" on a device inventory ?


HI 

 

I checked and yes it does list a AADUserID


Forum|alt.badge.img+7
  • Valued Contributor
  • January 19, 2022

HI 

 

I checked and yes it does list a AADUserID


Hey Harrie,

I apologize for replying so late. Is your script now returning the enrolled AADUSERID user? If you go to the .info file does it show a user enrolled? - 

/Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info

EngineerO
Forum|alt.badge.img+4
  • Contributor
  • February 16, 2022

HI 

 

I checked and yes it does list a AADUserID


hey, 

 

try this. Levi forgot to add quotes around the file path :) And I adjusted the way to get the current user as  the command above also showed other users logged in.

 

#!/bin/sh loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}') AADUSERID="$(/usr/libexec/PlistBuddy -c Print "/Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info" | grep aadUserId | cut -d '=' -f2 | xargs)" if [[ "${AADUSERID}" == "" ]] ; then /bin/echo "<result>None</result>" else /bin/echo "<result>${AADUSERID}</result>" fi exit 0

 


Forum|alt.badge.img+8
  • Contributor
  • February 16, 2022

hey, 

 

try this. Levi forgot to add quotes around the file path :) And I adjusted the way to get the current user as  the command above also showed other users logged in.

 

#!/bin/sh loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}') AADUSERID="$(/usr/libexec/PlistBuddy -c Print "/Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info" | grep aadUserId | cut -d '=' -f2 | xargs)" if [[ "${AADUSERID}" == "" ]] ; then /bin/echo "<result>None</result>" else /bin/echo "<result>${AADUSERID}</result>" fi exit 0

 


This seems to work

 

thnx


Forum|alt.badge.img+4
  • New Contributor
  • March 25, 2022

hey, 

 

try this. Levi forgot to add quotes around the file path :) And I adjusted the way to get the current user as  the command above also showed other users logged in.

 

#!/bin/sh loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}') AADUSERID="$(/usr/libexec/PlistBuddy -c Print "/Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info" | grep aadUserId | cut -d '=' -f2 | xargs)" if [[ "${AADUSERID}" == "" ]] ; then /bin/echo "<result>None</result>" else /bin/echo "<result>${AADUSERID}</result>" fi exit 0

 


Thanks for the tip! The quotes did the trick!


Forum|alt.badge.img
  • New Contributor
  • September 15, 2022

hey, 

 

try this. Levi forgot to add quotes around the file path :) And I adjusted the way to get the current user as  the command above also showed other users logged in.

 

#!/bin/sh loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}') AADUSERID="$(/usr/libexec/PlistBuddy -c Print "/Users/$loggedInUser/Library/Application Support/com.microsoft.CompanyPortalMac.usercontext.info" | grep aadUserId | cut -d '=' -f2 | xargs)" if [[ "${AADUSERID}" == "" ]] ; then /bin/echo "<result>None</result>" else /bin/echo "<result>${AADUSERID}</result>" fi exit 0

 


You can also get PlistBiddy to print the value directly instead of parsing it out:

 

loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}') AADUSERID="$(/usr/libexec/PlistBuddy -c 'Print:aadUserId' /Users/$loggedInUser/Library/Application\\ Support/com.microsoft.CompanyPortalMac.usercontext.info)" if [[ "${AADUSERID}" == "" ]] ; then /bin/echo "<result>None</result>" else /bin/echo "<result>${AADUSERID}</result>" fi exit 0