public void Execute(IActivityRequest request, IActivityResponse response) { SCCMServer = settings.SCCMSERVER; userName = settings.UserName; password = settings.Password; String pkgID = request.Inputs["Existing Package ID"].AsString(); String selectionMethod = request.Inputs["Distribution Point Selection Method"].AsString(); String criteria = request.Inputs["Selection Criteria"].AsString(); String NALPathQuery = request.Inputs["NALPath Query (Single DP)"].AsString(); //Setup WQL Connection and WMI Management Scope WqlConnectionManager connection = CMInterop.connectSCCMServer(SCCMServer, userName, password); using (connection) { switch (selectionMethod) { case "Single Distribution Point": if (criteria.Equals(String.Empty) || NALPathQuery.Equals(String.Empty)) { response.LogErrorMessage("Must use optional property 'Selection Criteria' with Single DP Selection. Criteria should be DP Name to refresh Package at. Must also provide a NALPathQuery"); } else { IResultObject obj = CMInterop.getSCCMComputer(connection, "", criteria, ""); foreach (IResultObject comp in obj) { system DP = new system(comp); bool success = false; foreach (String siteCode in DP.AgentSite.Split(',')) { try { CMInterop.assignSCCMPackageToDistributionPoint(connection, pkgID, siteCode, criteria, NALPathQuery); success = true; break; } catch { } } if (!success) { throw new Exception("Failed to assign package to DP"); } } } break; case "Distribution Point Group": if (criteria.Equals(String.Empty)) { response.LogErrorMessage("Must use optional property 'Selection Criteria' with DP Group Selection. Criteria should be DP Group Name to Assign Package to"); } else { CMInterop.assignSCCMPackageToDistributionPointGroup(connection, pkgID, criteria); } break; case "All Distribution Points": CMInterop.assignSCCMPackageToAllDistributionPoints(connection, pkgID); break; } response.Publish("Package ID", pkgID); } }