Skip to main content
Question

Smart Computer Group API


Forum|alt.badge.img+3

Hey JAMFs!
I try to automate the creation of Smart Computer Groups by API (within Powershell) based on the installed Apps criteria.

I'm a bit confused as I don't find anything in the API-documentation fpr smart-computer-group with method POST.

I already have a filtered list of all required groups with app name, path and name for the group.

4 replies

Tangentism
Forum|alt.badge.img+10
  • Honored Contributor
  • 144 replies
  • February 12, 2024

The API reference has it under 'Computer Groups' and one of the tags is to define if its a smart group or not:

 

https://developer.jamf.com/jamf-pro/reference/createcomputergroupbyid


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 7 replies
  • February 12, 2024

Thanks, I didn't find the reference at first, only had the short documentation.
I managed to create the "sync".
My next goal would be a match against the Labels.txt of the installomator, what really isn't that simple as I hoped....


MikePh
Forum|alt.badge.img+4
  • Employee
  • 16 replies
  • February 12, 2024

Depends how automated you're looking to go. Creating a script to create the smart computer groups off a list that you feed the script (whether a file or manually putting it in) wouldn't be too bad. If you want to pull that information from somewhere that may be harder. 

You can't access the ... list of the installed apps criteria, you'd need to for example pick a computer and then use an API call to pull all the apps that it has (assuming it has the full list of apps you'd want)


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 7 replies
  • February 13, 2024

It works so far:

$clientid = "<clientid>" $clientsecret = "<cleintsecret>" $baseURL = "https://<yourcompany>.jamfcloud.com" $body = @{ client_id = $clientid client_secret= $clientsecret grant_type='client_credentials' } try { $token=Invoke-WebRequest -Uri $baseURL"/oauth/token" -ContentType "application/x-www-form-urlencoded" -Body $body -Method POST } Catch [System.Net.WebException] { $exception = $_.Exception $respstream = $exception.Response.GetResponseStream() $sr = new-object System.IO.StreamReader $respstream $ErrorResult = $sr.ReadToEnd() write-host $ErrorResult } $token = $token.Content | ConvertFrom-Json $token = $token.access_token $auth = "Bearer $token" $AllEntries = Invoke-WebRequest -Uri $baseurl"/api/v1/computers-inventory?section=APPLICATIONS&page=0&page-size=100&sort=general.name%3Aasc" -Headers @{Authorization=$auth} -ContentType "application/json" -Method GET -Verbose $AllEntries = $AllEntries.Content $AllEntries = $AllEntries | ConvertFrom-Json foreach ($Computerentry in $AllEntries.results) { foreach ($appentry in $Computerentry.applications) { if ($appentry.path -notlike "/System/*") { Write-Host $appentry.name Write-Host $appentry.path $Groupname = "Software - "+$appentry.name.Replace(".app","") Write-Host $Groupname $xml=" <computer_group> <name>"+$Groupname+"</name> <is_smart>true</is_smart> <site> <id>-1</id> <name>None</name> </site> <criteria> <size>1</size> <criterion> <name>Application Title</name> <priority>0</priority> <and_or>and</and_or> <search_type>is</search_type> <value>"+$appentry.name+"</value> <opening_paren>false</opening_paren> <closing_paren>false</closing_paren> </criterion> </criteria> </computer_group>" Invoke-WebRequest -uri $baseurl"/JSSResource/computergroups/id/0" -Headers @{Authorization=$auth} -ContentType "application/xml" -body $xml -Method POST } } }

 Challenge now is to match the App-Names to the labels of installomator.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings