public void Execute(IActivityRequest request, IActivityResponse response) { SCCMServer = settings.SCCMSERVER; userName = settings.UserName; password = settings.Password; String objID = request.Inputs["Collection ID"].AsString(); String ruleName = request.Inputs["Rule Name"].AsString(); String wqlQuery = request.Inputs["WQL Query"].AsString(); String limitCollectionID = String.Empty; if (request.Inputs.Contains("Collection ID to Limit Query To")) { limitCollectionID = request.Inputs["Collection ID to Limit Query To"].AsString(); } //Setup WQL Connection and WMI Management Scope WqlConnectionManager connection = CMInterop.connectSCCMServer(SCCMServer, userName, password); using (connection) { CMInterop.addSCCMCollectionRule(connection, objID, ruleName, wqlQuery, limitCollectionID); IResultObject col = null; col = CMInterop.getSCCMCollection(connection, "CollectionID LIKE '" + objID + "'"); if (col != null) { response.WithFiltering().PublishRange(getObjects(col)); } response.Publish("Number of Collections", ObjCount); } }