Tim Johnson wrote: > import wmi > site = 'MV1' > wmi_server = 'mtv-sql-2' > resource = 23012 > wmi_namespace = 'root\\sms\\site_%s' % site > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace) > coll = conn.Get('SMS_Collection.CollectionID="MV100362"') > rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_() > rule.ResourceID = resource > rule.RuleName = 'ResourceID: ' +str(resource) > rule.ResourceClassName = 'SMS_R_System' > coll.AddMembershipRule(rule)
As an aside from the error messages you're getting, the wmi module has some slightly more Pythonic support for what you're doing there. Something like this (untested) should work: <code - untested> import wmi site = 'MV1' wmi_server = 'mtv-sql-2' resource = 23012 conn = wmi.WMI (computer=smi_server, namespace="sms/site_%s" % site) coll = conn.get ('SMS_Collection.CollectionID="MV100362"') # # or, using the more common wmi idiom # # coll = conn.SMS_Collection (CollectionID="MV100362")[0] rule = conn.SMS_CollectionRuleDirect.new ( ResourceID=resource, RuleName="ResourceID: " + str (resource), ResourceClassName = "SMS_R_System" ) coll.AddMembershipRule (rule) </code> FWIW, this stuff is covered in the tutorial: http://timgolden.me.uk/python/wmi-tutorial.html#creating-wmi-objects Obviously, your code should also work as the module simply passes the .Get method call through to the underlying WMI object. It also, as a matter of fact, offers a local version .get which wraps the result. The wrapped version is handy if you want to do things with the properties and methods, but offers little if you're just passing the whole thing along as an opaque object. TJG _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32