The solution at the bottom of this post may help: https://www.jamf.com/jamf-nation/discussions/20957/differentiate-between-a-mac-app-store-app-installed-via-the-app-store-or-vpp
@timlarsen Thank you for the link! Based on the information I found here and on @charles.edge 's excellent Krypted post I went about crafting this. Run as a script on a local machine It will find any MAS Apps that were purchased through VPP and, who the owner of that app is. The reason for sussing out the owner is after an acquisition, we have apps purchased by company A and Company B. It's useful to know which account is attached to the VPP apps. Here's my question, returning AppName and AppOwner in the same result is giving me unexpected results. Is it possible to have a Result1=AppName and a Result2=AppOwner in an EA?
Feel free to use this if you find it useful.
#!/bin/bash
#
# JAMF Extension Attribute that finds any MAS apps
# that were purchased through VPP and which account
# purchased it.
# www.pretendco.com
VPPApps=$( mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "1"')
AppOwner=$( mdls "$VPPApps" -name kMDItemAppStoreReceiptOrganizationDisplayName | awk '{ print $3, $4 }' | sed -e 's/^"//' -e 's/"$//')
AppName=$( echo "$VPPApps" | awk -F'/' '{print $NF}' | sed -e 's/^"//' -e 's/"$//')
result="$AppOwner $AppName"
echo "<result>$result</result>"
Ooops! I didn't account for spaces in the application names. So, with an assist from @greg.mcmullen on the #bash channel on MacAdmins.org's slack, that problem is fixed. Here is the new and improved EA. Although the more I think about it I wonder if I should make two EA's...
#!/bin/bash
#
# JAMF Extension Attribute that finds any MAS apps
# that were purchased through VPP and which account
# purchased it.
# Crafted by Craig Lindsey for Starz 2017-2-10
#
mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "1"' | while read VPPApp; do
AppOwner=$( mdls "$VPPApp" -name kMDItemAppStoreReceiptOrganizationDisplayName | awk '{ print $3, $4 }' | sed -e 's/^"//' -e 's/"$//' )
AppName=$( echo "$VPPApp" | awk -F'/' '{print $NF}' | sed -e 's/^"//' -e 's/"$//')
result="$AppName $AppOwner"
echo "<result>$result</result>"
done