Пример #1
0
        private void btnAddRequirement_Click(object sender, EventArgs e)
        {
            this.SetNamedScopeForSCCMRequest();
            ////retrieve the global condition to be associated by name
            WqlQueryResultsObject results = this.sccmConnection.QueryProcessor.ExecuteQuery(string.Format("SELECT * FROM SMS_GlobalCondition Where LocalizedDisplayName = '{0}'", cmbConditions.Items[cmbConditions.SelectedIndex])) as WqlQueryResultsObject;
            IResultObject         result  = null;

            foreach (IResultObject item in results)
            {
                result = item;
                break;
            }
            ////retrieve the application to add the global condition onto be name
            sccm.Application application = GetApplicationFromName(txtSCCMApplicationName.Text);
            if (result != null && application != null && application.DeploymentTypes.Any())
            {
                ////need to get all the information for the result otherwise the call to the dcmobjectwrapper wont work
                result.Get();
                ////Get the full id from the property of the result object
                string ciuniqueid = result.PropertyList["CI_UniqueID"];
                ////It will contain the scope and ID which, both of which are needed seperately so split them on their seperator
                string[] ids   = ciuniqueid.Split("/".ToCharArray());
                string   scope = ids[0];
                string   id    = ids[1];

                ////wrap up the wmi object in a wrapper object so it is possible to read out particular seetings
                DcmObjectWrapper dcmwrapper      = DcmObjectWrapper.WrapExistingConfigurationItem(result) as DcmObjectWrapper;
                ComplexSetting   complexsettings = dcmwrapper.InnerConfigurationItem.Settings;
                string           name            = complexsettings.ChildSimpleSettings[0].LogicalName;

                ////create the operands object which will set up ther comparison information
                CustomCollection <ExpressionBase> operands = new CustomCollection <ExpressionBase>();
                ////Add the reference information to the global setting - note the assumption it is a string (this could also be read out of the object above)
                GlobalSettingReference setting = new GlobalSettingReference(scope, id, ScalarDataType.String, name, ConfigurationItemSettingSourceType.CIM);
                setting.SettingSourceType = ConfigurationItemSettingSourceType.Registry;
                setting.MethodType        = ConfigurationItemSettingMethodType.Value;
                ////add the value into the value for the registry entry, note this example just focuses on string registry settings
                ConstantValue value = new ConstantValue(txtRequirementValue.Text, ScalarDataType.String);
                operands.Add(setting);
                operands.Add(value);
                ////for this example this requirement will check to see if something is of a particular value
                Expression exp = new Expression(ExpressionOperator.IsEquals, operands);
                ////Create a rule to add to the deplyment types requirement list
                Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Rule rule = new Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Rule("Rule_" + Guid.NewGuid().ToString("B").Replace("{", string.Empty).Replace("}", string.Empty), Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.NoncomplianceSeverity.None, null, exp);
                application.DeploymentTypes[0].Requirements.Add(rule);
                ////save the changes back to SCCM
                SaveApplication(application);
            }
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();
            ////connect to sccm
            this.sccmConnection.Connect(Environment.MachineName);
            ////retrieve the current applications and add them to the supersedence/dependency drop downs
            string wmiQuery = "SELECT * FROM SMS_Application WHERE SMS_APPLICATION.IsLatest = 1";
            WqlQueryResultsObject applicationResults = this.sccmConnection.QueryProcessor.ExecuteQuery(wmiQuery) as WqlQueryResultsObject;

            foreach (WqlResultObject appReference in applicationResults)
            {
                this.cmbSuperseded.Items.Add(appReference["LocalizedDisplayName"].StringValue);
                this.cmbDependency.Items.Add(appReference["LocalizedDisplayName"].StringValue);
            }

            ////get the global conditions and them to the global conditions drop down
            string condtionQuery = string.Format("SELECT * FROM SMS_GlobalCondition");
            WqlQueryResultsObject queryResults = this.sccmConnection.QueryProcessor.ExecuteQuery(condtionQuery) as WqlQueryResultsObject;

            foreach (IResultObject condition in queryResults)
            {
                ////retireve the lazy properties from the global condition
                condition.Get();
                ////load into wrapper objects so we can read out the properties in more detail
                DcmObjectWrapper wraper            = DcmObjectWrapper.WrapExistingConfigurationItem(condition) as DcmObjectWrapper;
                ComplexSetting   conditionSettings = wraper.InnerConfigurationItem.Settings;
                if (conditionSettings.ChildSimpleSettings.Any())
                {
                    ////if the condition contains simplechild settings assume this is a registry setting
                    RegistrySetting registrySetting = conditionSettings.ChildSimpleSettings[0] as RegistrySetting;
                    if (registrySetting != null)
                    {
                        ScalarDataType type = registrySetting.SettingDataType as ScalarDataType;
                        ////only add string based registry conditions
                        if (type == ScalarDataType.String)
                        {
                            this.cmbConditions.Items.Add(registrySetting.Name);
                        }
                    }
                }
            }

            ////get the available distribution point groups and add them to the drop down
            string dpgQuery            = "Select * From SMS_DistributionPointGroup";
            WqlQueryResultsObject dpgs = this.sccmConnection.QueryProcessor.ExecuteQuery(dpgQuery) as WqlQueryResultsObject;

            foreach (WqlResultObject dpg in dpgs)
            {
                this.cmbDPGNames.Items.Add(dpg["Name"].StringValue);
            }

            ////get a list of the avialable collections
            string collectionQuery            = "SELECT * FROM SMS_Collection";
            WqlQueryResultsObject collections = this.sccmConnection.QueryProcessor.ExecuteQuery(collectionQuery) as WqlQueryResultsObject;

            foreach (WqlResultObject collection in collections)
            {
                this.cmbCollection.Items.Add(collection.PropertyList["Name"]);
            }

            if (this.cmbSuperseded.Items.Count > 0)
            {
                this.cmbSuperseded.SelectedIndex = 0;
                this.cmbDependency.SelectedIndex = 0;
            }

            if (this.cmbConditions.Items.Count > 0)
            {
                this.cmbConditions.SelectedIndex = 0;
            }

            if (this.cmbDPGNames.Items.Count > 0)
            {
                this.cmbDPGNames.SelectedIndex = 0;
            }

            if (this.cmbCollection.Items.Count > 0)
            {
                this.cmbCollection.SelectedIndex = 0;
            }
        }