-
Notifications
You must be signed in to change notification settings - Fork 30
CSV file from Saved Advanced Computer Search
Chris Lasell edited this page Sep 24, 2019
·
1 revision
Create and save an advanced search, with whatever display fields you'd like
Then in the script below, change the values for JSS_SERVER, JSS_USER , ADV_SEARCH_NAME, & OUTFILE as appropriate.
When you run the script you'll be prompted for the password to connect JSS_USER to JSS_SERVER, then the csv file will be created at OUTFILE.
You may need to add more connection settings (e.g. port, ssl_version) for your environment
#!/usr/bin/ruby
require 'ruby-jss'
JSS_SERVER = 'myjss.myplace.org'
JSS_USER = 'reportUser'
ADV_SEARCH_NAME = 'Some Saved Search'
OUTFILE = '/tmp/adv_search_results.csv'
JSS.api.connect server: JSS_SERVER, user: JSS_SERVER, pw: :prompt
search = JSS::AdvancedComputerSearch.fetch(name: ADV_SEARCH_NAME)
search.export OUTFILE # format defaults to CSV
# That's it!
# For an example of using ruby's CSV library yourself:
require 'csv'
search_results = search.search_results
fields = search_results.sample.keys
CSV.open(OUTFILE, "wb") do |csv|
csv << fields
search_results.each do |result|
csv << result.values
end
end