Skip to content
Chris Lasell edited this page Oct 31, 2019 · 2 revisions
# This is a collection of all the lines that will be pasted in during the lab session

require 'ruby-jss'
require 'pp'

JSS.api.connect server: 'tryitout.jamfcloud.com', user: 'jnuc2019', pw: :prompt

JSS::ComputerGroup.all.sample

pp JSS::ComputerGroup.all ;0

JSS::ComputerGroup.all.each { |grp_data| puts grp_data[:name] } ;0

JSS::ComputerGroup.all.each do |grp_data|
  next if grp_data[:is_smart]
  puts "Static Group Name: #{grp_data[:name]}, ID:  #{grp_data[:id]}"
end ;0

JSS::ComputerGroup.all_smart.each { |grp_data| puts grp_data[:name] } ;0

pp JSS::MobileDevice.all_supervised ;0

pp JSS::DistributionPoint.all_names ;0

pp JSS::MobileDevice.all_wifi_mac_addresses ;0

pp JSS::MobileDevice.all_wifi_mac_addresses ;0

pp JSS::MobileDevice.all_wifi_mac_addresses :refresh ;0

mgd_laptops = JSS::Computer.all_laptops.select { |macinfo| macinfo[:managed] } ;0

pp mgd_laptops ;0

mgd_laptops.size

mgd_laptop_users = mgd_laptops.map { |macinfo| macinfo[:username] }  ;0

pp mgd_laptop_users ;0

mgd_supd_ipads = JSS::MobileDevice.all_ipads.select { |ipad| ipad[:managed] && ipad[:supervised] } ;0

mgd_supd_ipads.each do |ipad_data|
  next unless mgd_laptop_users.include? ipad_data[:username]
  puts "iPad: '#{ipad_data[:name]}' SN: '#{ipad_data[:serial_number]}' User: '#{ipad_data[:username]}' has a managed Mac laptop"
end ;0

pp JSS::NetworkSegment.all ;0

JSS::NetworkSegment.all_ids.each do |ns_id|
  net_seg = JSS::NetworkSegment.fetch id: ns_id
  next unless net_seg.distribution_point
  puts "Name: '#{net_seg.name}'\n  Dist. Point: '#{net_seg.distribution_point}'"
  sleep (rand + 1)
end ;0

grp_name = 'my-awesome-computer-group'

my_grp = JSS::ComputerGroup.make name: grp_name, type: :static ;0

pp my_grp ;0

my_grp_id = my_grp.save

comp_base_name = 'my-awesome-computer'

new_comp_ids = []

5.times do |pass_num|
  comp_name = "#{comp_base_name}-#{pass_num}"

  comp_sn = comp_name + "-sn"

  comp_udid = `uuidgen`.chomp

  comp = JSS::Computer.make name: comp_name, sn: comp_sn, udid: comp_udid; 0

  new_comp_ids << comp.save

  puts "Created Computer '#{comp_name}'"
  puts "  id: #{new_comp_ids.last}"
  puts "  sn: #{comp_sn}"
  puts "  udid: #{comp_udid}"
end

pp JSS::Computer.all_names(:refresh).select { |name| name.start_with? comp_base_name } ;0

my_grp.change_membership add_members: new_comp_ids

ea_name = 'JNUC-2019-LabUser'

ea_value = 'Jeaux Bleaux'

my_grp.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 "Changed EA '#{ea_name}' from '#{orig_val}' to '#{ea_value}' for computer '#{computer.name}' "

  sleep (rand + 1)
end

comp_to_check = JSS::Computer.fetch id: my_grp.member_ids.sample ;0

comp_to_check.ext_attrs[ea_name]

comp_to_check.delete

JSS::Computer.delete my_grp.member_ids

JSS::ComputerGroup.make(name: 'ChrissVIP-Computers', type: :static).save ;0

JSS::MobileDeviceGroup.make(name: 'ChrissVIP-Devices', type: :static).save ;0

pp JSS::ComputerGroup.fetch(name: 'ChrissVIP-Computers').member_names ;0

pp JSS::MobileDeviceGroup.fetch(name: 'ChrissVIP-Devices').member_names ;0
Clone this wiki locally