Posted on 08-21-2024 02:01 AM
Hey Guys,
I´m currently looking to get a List of Static Groups from a specific computer.
I found the API command: v1/computers-inventory-detail/{id} getting a large JSON with the Details.
Now I want to cut it down to:
1. only the Arrays from Key "groupMemberships"
2. maybe to all Arrays with "smartGroup=false"
I tried with plutil -extract, but I cant get the right Keypath...
Here is an example of my JSON:
"id" : "866",
"udid" : "6A94F1BD-XXXX-XXXXX-XXXX-ECB58DFA0B61",
"general" : {
"name" : "MC-XXXXXXXX",
"lastIpAddress" : "XX.XX.XX.XX",
"lastReportedIp" : "XX.XX.XXX.XX",
"jamfBinaryVersion" : "11.7.1-t1721056075",
"platform" : "Mac",
"barcode1" : null,
"barcode2" : null,
"assetTag" : null,
"remoteManagement" : {
"managed" : true,
"managementUsername" : null
},
"supervised" : true,
"mdmCapable" : {
"capable" : true,
"capableUsers" : [ "XXXXXX" ]
},
"reportDate" : "2024-08-21T06:55:17.421Z",
"lastContactTime" : "2024-08-21T08:41:21.63Z",
"lastCloudBackupDate" : null,
"lastEnrolledDate" : "2024-07-01T08:28:35.256Z",
"mdmProfileExpiration" : "2026-07-01T08:27:37Z",
"initialEntryDate" : "2024-07-01",
"distributionPoint" : null,
"site" : {
"id" : "-1",
"name" : "None"
}
"diskEncryption" : {
"individualRecoveryKeyValidityStatus" : "VALID",
"institutionalRecoveryKeyPresent" : false,
"diskEncryptionConfigurationName" : "FileVault_TK",
"fileVault2EligibilityMessage" : "Eligible",
"fileVault2EnabledUserNames" : [ "P231180" ],
"bootPartitionEncryptionDetails" : {
"partitionName" : "Macintosh HD (Boot Partition)",
"partitionFileVault2State" : "ENCRYPTED",
"partitionFileVault2Percent" : 100
}
"plugins" : [ ],
"groupMemberships" : [ {
"groupId" : "1",
"groupName" : "All Managed Clients",
"smartGroup" : true
}, {
"groupId" : "12",
"groupName" : "DEP enrolled Client",
"smartGroup" : true
}, {
"groupId" : "15",
"groupName" : "ComputerName",
"smartGroup" : true
}, {
"groupId" : "18",
"groupName" : "FileVault",
"smartGroup" : true
}, {
"groupId" : "20",
"groupName" : "NameSet",
"smartGroup" : true
}, {
"groupId" : "23",
"groupName" : "Adobe_CreativeCloud",
"smartGroup" : false
}, {
"groupId" : "255",
"groupName" : "Pilots",
"smartGroup" : false
}, {
"groupId" : "256",
"groupName" : "TS.CA Pilot",
"smartGroup" : false
} ],
Solved! Go to Solution.
Posted on 08-22-2024 03:15 AM
Solved it in an rookie way :D
As I just needed the values of the GroupIDs I got an textfile as output and greped it the way I needed
here is the cut out with variables:
# Inventory Collection from Computer
inventory_details=$(curl -s -H "Accept: application/json" -H "Authorization: Bearer ${bearerToken}" "${url}/api/v1/computers-inventory-detail/$deviceID" -X GET)
echo "$inventory_details" >> $txt_tmp
# Use grep to delete everything except 2 Lines with: "smartGroup" : false
grep -B 2 '"smartGroup" : false' $txt_tmp > $txt_tmp2
# cutting only Group IDs and writing into txt file
awk -F'"' '/"groupId" :/ {print $4}' $txt_tmp2 > $GROUP_ID_FILE
Posted on 08-21-2024 05:43 AM
I can see a couple ways to do this.
A simple way would be to use grep and its --before-context option to find “smartGroup” : false and then clean up the results with sed.
Or you could use xpath and its preceding-sibling syntax, which is a little more complicated but would result in cleaner results with one command. I have an example of how to do this with following-sibling here:
https://gist.github.com/talkingmoose/07ae935169e863b377c2290c40a660e0
Posted on 08-22-2024 03:15 AM
Solved it in an rookie way :D
As I just needed the values of the GroupIDs I got an textfile as output and greped it the way I needed
here is the cut out with variables:
# Inventory Collection from Computer
inventory_details=$(curl -s -H "Accept: application/json" -H "Authorization: Bearer ${bearerToken}" "${url}/api/v1/computers-inventory-detail/$deviceID" -X GET)
echo "$inventory_details" >> $txt_tmp
# Use grep to delete everything except 2 Lines with: "smartGroup" : false
grep -B 2 '"smartGroup" : false' $txt_tmp > $txt_tmp2
# cutting only Group IDs and writing into txt file
awk -F'"' '/"groupId" :/ {print $4}' $txt_tmp2 > $GROUP_ID_FILE