Jamf Pro API - Bulk ADD and Remove computers from static group assignments

tegus232
Contributor

I am new to Jamf Pro API and I am diving into more and more automations. 

 

Can someone help me with how i would go about to updating multiple computer assignments for a static group by using computer names. If you have a working script, please assist. maybe via csv file?

1 ACCEPTED SOLUTION

talkingmoose
Moderator
Moderator

You may want to use The MUT found in the Mac App Store. Requires no scripting knowledge.

https://apps.apple.com/us/app/mut/id1133234759?mt=12

View solution in original post

3 REPLIES 3

talkingmoose
Moderator
Moderator

You may want to use The MUT found in the Mac App Store. Requires no scripting knowledge.

https://apps.apple.com/us/app/mut/id1133234759?mt=12

Been using MUT for a few years now, very happy with it, though I always get the "need to use classic method" verbiage and if I want to run it that way and I always say yes. 

Kinda wish, I could make that the default, but either way, great program. 

ChrisL
New Contributor III

If you still want a scripted solution, and you are familiar with, or willing to use, ruby as your programming language, ruby-jss makes doing things like this very easy: 

 

#!/usr/bin/env ruby
require 'ruby-jss'
require 'csv'

# This csv file contains the computers that should be in the group
# Computer names are in the first field of this csv file.
# Get the names into an array

desired_comp_names = CSV.read('/path/to/computernames.csv').map(&:first)

# connect to Jamf Pro
# you'll be prompted for the password, or it can be given with the 'connect' command

Jamf.connect 'https://apiuser@myjamfhost.jamfcloud.com'

# get the group by name

static_group = Jamf::ComputerGroup.fetch name: 'StaticGroupName'

# replace any existing membership with the desired names

static_group.members = desired_comp_names

# save your changes

static_group.save

Five lines of code, not counting the shebang and 'require' lines.