# # ruby-wbem sample code # # Get instance # # Written by Klaus Kämpf 2015 # $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) require 'wbem' def usage msg = nil if msg STDERR.puts "** Err: #{msg}" STDERR.puts "Usage:" STDERR.puts "get [-d] = [= ...]" exit 1 end end def connect url usage " missing" unless url return Wbem::Client.connect url end url = ARGV.shift if url == "-d" Wbem.debug = -1 url = ARGV.shift end usage " missing" unless url klass = ARGV.shift usage " missing" unless klass args = {} while arg = ARGV.shift k,v = arg.split("=") usage "Bad = pair" unless k && v args[k] = v end usage "needs at least one = pair" if args.empty? client = connect url instance = client.get klass, args if instance puts "#{instance.class}: #{instance}\n" else puts "Not found" end