/// <summary> /// Sets the named scope for SCCM request. /// </summary> private void SetNamedScopeForSCCMRequest() { ////need to set the scope for the application request WqlResultObject smsIdentification = this.sccmConnection.GetClassObject("sms_identification") as WqlResultObject; string id = smsIdentification.ExecuteMethod("GetSiteID", null)["SiteID"].StringValue.Replace("{", string.Empty).Replace("}", string.Empty); NamedObject.DefaultScope = "ScopeId_" + id; }
public static void RemoveDeployment(string collectionId) { try { WqlResultObject collSettings = null; var wmiQuery = $"SELECT * FROM SMS_CollectionSettings WHERE CollectionID='{collectionId}'"; var result = Globals.Sccm.QueryProcessor.ExecuteQuery(wmiQuery) as WqlQueryResultsObject; foreach (WqlResultObject coll in result) { collSettings = coll; break; } if (collSettings == null) { return; } collSettings.Get(); var collVars = collSettings.GetArrayItems("CollectionVariables"); var newList = new List <IResultObject>(); foreach (var v in collVars) { if (!v["Name"].StringValue.Contains("DPLSCH")) { newList.Add(v); } } collSettings.SetArrayItems("CollectionVariables", newList); collSettings.Put(); } catch (SmsQueryException ex) { Logger.Log(ex.Details, LogType.Error); } catch (SmsException ex) { Logger.Log(ex.Details, LogType.Error); } catch (Exception ex) { Logger.Log(ex.Message, LogType.Error); } }
private void btnDeploy_Click(object sender, EventArgs e) { ////retrieve the application WqlResultObject application = GetApplicationWQLFromName(txtSCCMApplicationName.Text); if (application != null) { ////get the collection we want to apply to the deployment string collectionQuery = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM SMS_Collection Where Name = '{0}'", cmbCollection.Items[cmbCollection.SelectedIndex]); WqlQueryResultsObject collections = this.sccmConnection.QueryProcessor.ExecuteQuery(collectionQuery) as WqlQueryResultsObject; WqlResultObject result = null; foreach (WqlResultObject collection in collections) { result = collection; } ////create an assignment (deployment) using the application and collection details if (result != null) { IResultObject applicationAssignment = this.sccmConnection.CreateInstance("SMS_ApplicationAssignment"); DateTime time = DateTime.Now; //// assign the application information to the assignment applicationAssignment["ApplicationName"].StringValue = application.PropertyList["LocalizedDisplayName"]; applicationAssignment["AssignedCI_UniqueID"].StringValue = application.PropertyList["CI_UniqueID"]; applicationAssignment["AssignedCIs"].IntegerArrayValue = new int[] { int.Parse(application.PropertyList["CI_ID"]) }; applicationAssignment["AssignmentName"].StringValue = this.txtSCCMApplicationName.Text + "_Deployment"; ////use the collection name applicationAssignment["CollectionName"].StringValue = result.PropertyList["Name"]; applicationAssignment["DisableMomAlerts"].BooleanValue = true; applicationAssignment["AssignmentDescription"].StringValue = "Created by a web form application"; applicationAssignment["EnforcementDeadline"].DateTimeValue = time; applicationAssignment["NotifyUser"].BooleanValue = false; applicationAssignment["OfferFlags"].LongValue = 1; applicationAssignment["DesiredConfigType"].LongValue = 1; applicationAssignment["OverrideServiceWindows"].BooleanValue = false; applicationAssignment["RebootOutsideOfServiceWindows"].BooleanValue = false; applicationAssignment["RequireApproval"].BooleanValue = false; applicationAssignment["StartTime"].DateTimeValue = time; applicationAssignment["SuppressReboot"].LongValue = 0; ////use the collection id applicationAssignment["TargetCollectionID"].StringValue = result.PropertyList["CollectionID"]; applicationAssignment["UseGMTTimes"].BooleanValue = false; applicationAssignment["UserUIExperience"].BooleanValue = false; applicationAssignment["WoLEnabled"].BooleanValue = false; applicationAssignment["LocaleID"].LongValue = 1033; applicationAssignment.Put(); } } }
/// <summary> /// Gets the name of the application from. /// </summary> /// <param name="applicationName">Name of the application.</param> /// <param name="onlyLatest">if set to <c>true</c> [only latest].</param> /// <returns></returns> private sccm.Application GetApplicationFromName(string applicationName) { WqlResultObject appReference = GetApplicationWQLFromName(applicationName); if (appReference != null) { ////load all the properties for the application object so it can be loaded into an AppManWrapper to retrive application appReference.Get(); ApplicationFactory applicationFactory = new ApplicationFactory(); AppManWrapper applicationWrapper = AppManWrapper.WrapExisting(appReference, applicationFactory) as AppManWrapper; return(applicationWrapper.InnerAppManObject as sccm.Application); } return(null); }
private void btnDistribute_Click(object sender, EventArgs e) { WqlResultObject application = GetApplicationWQLFromName(txtSCCMApplicationName.Text); if (application != null) { ////get the package ids associated with the application string packageQuery = "SELECT PackageID FROM SMS_ObjectContentInfo WHERE ObjectID='" + application.PropertyList["ModelName"] + "'"; IResultObject packages = this.sccmConnection.QueryProcessor.ExecuteQuery(packageQuery); List <string> idList = new List <string>(); if (packages != null) { foreach (IResultObject package in packages) { idList.Add(package.PropertyList["PackageID"]); } } ////return the selected distribution point group string dpgQuery = string.Format(CultureInfo.InvariantCulture, "Select * From SMS_DistributionPointGroup Where Name = '{0}'", cmbDPGNames.Items[cmbDPGNames.SelectedIndex]); WqlQueryResultsObject dpgresults = this.sccmConnection.QueryProcessor.ExecuteQuery(dpgQuery) as WqlQueryResultsObject; WqlResultObject result = null; foreach (WqlResultObject dpgresult in dpgresults) { result = dpgresult; } if (result != null) { ////send them to the distribution point group Dictionary <string, object> methodParams = new Dictionary <string, object>(); methodParams["PackageIDs"] = idList.ToArray(); result.ExecuteMethod("AddPackages", methodParams); } } }