-
Notifications
You must be signed in to change notification settings - Fork 30
JNUC2019 Lab Session E Quick Report
-
The Jamf Pro UI has a way to automate the generation of some kinds of reports. But occasionally you'll want something a bit more complex
-
For example, A report listing the device name, serial, and username for all iPads that are managed, and supervised, whose users also have a managed Mac laptop.
mgd_laptops = JSS::Computer.all_laptops.select { |macinfo| macinfo[:managed] } ;0
# => 0
pp mgd_laptops ;0
# [array of hashes]
# =>0
mgd_laptops.size
# => 85
-
Here we are using the
all_laptops
method to get the list of laptops -
But we only want the managed ones, so we use another iterator
select
to filter them out. -
Like
each
select loops thru and passes each hash into a block of code. -
as we loop thru,
select
remembers the ones where the code block evaluated totrue
-
our codeblock look at the
:managed
value in each array, which is true or false -
select
then returns a new array, with only the hashes that were 'true' -
and we store that in the variable
mdg_laptops
to use later.
mgd_laptop_users = mgd_laptops.map { |macinfo| macinfo[:username] } ;0
# => 0
pp mgd_laptop_users ;0
# [array of usernames]
# => 0
-
Now we're using yet another iterator:
map
-
This loops thru the Hashes in the array, building another array with the value calculated in the code block
-
Our code block is just extracting the :username value from the Hash
-
so we end up with an array of username, which we store in the var.
mgd_laptop_users
to use later
mgd_supd_ipads = JSS::MobileDevice.all_ipads.select { |ipad| ipad[:managed] && ipad[:supervised] } ;0
# => 0
-
here we're using
select
again, and using it on the Array ofall_ipads
. We're selecting the ipads thare are both managed and supervised -
and we're saving them in the var.
mgd_supd_ipads
mgd_supd_ipads.each do |ipad|
next unless mgd_laptop_users.include? ipad[:username]
puts "Supervised iPad '#{ipad[:name]}' SN: '#{ipad[:serial_number]}' - User '#{ipad[:username]}' has a managed Mac laptop"
end ;0
# [lines of output]
# => 0
-
and finally we put it all together using
each
to loop through our managed, supervised ipads -
we skip the ipad unless its user's name is in the list of laptop usernames we saved above
-
and then we print a line of output