Skip to content

JNUC2019 Lab Session I Changing EAs

Chris Lasell edited this page Oct 4, 2019 · 7 revisions

Changing and Extention Attribute for the Computers in a Group

  • here's something a bit more practical - Lets change an extension attribute value for all the members of our group

  • this would work for smart groups, as well as static groups.

  • first, fetch the gruop you're interested in - we'll use the group we just created

group = JSS::ComputerGroup.fetch name: grp_name ;0
# => 0
  • now, put the name and desired value for the ext. attrib. into variables. This EA already exists, so use this one

  • use your own name for the value

ea_name = 'JNUC-2019-LabUser'
# => "JNUC-2019-LabUser"

ea_value = 'Chris Lasell'
# => "Chris Lasell"
  • and now we loop through the group members, fetching each computer, setting the ea, and saving our change
group.member_ids.each do |comp_id|
  computer = JSS::Computer.fetch id: comp_id
  orig_val = computer.ext_attrs[ea_name]
  computer.set_ext_attr ea_name, ea_value
  computer.save
  puts "Set EA for computer '#{computer.name}' from '#{orig_val}' to #{ea_value}"
end
# [ lines of output]
# => [ array of member ids, from 'each' ]
  • To check our work, re-fetch one of the computers, and look at the value
comp_to_check = JSS::Computer.fetch id: group.member_ids.sample ;0
# => 0

comp_to_check.ext_attrs[ea_name]
# => "Chris Lasell"
Clone this wiki locally