예제 #1
0
        private bool CreateDriverCategory()
        {
            categoryObject = GetDriverCategory();

            if (categoryObject == null)
            {
                IResultObject instance = connectionManager.CreateInstance("SMS_CategoryInstance");
                instance["CategoryInstance_UniqueID"].StringValue = string.Format("DriverCategories: {0}", Guid.NewGuid().ToString());
                instance["CategoryTypeName"].StringValue          = "DriverCategories";
                List <IResultObject> list = new List <IResultObject>();
                IResultObject        embeddedObjectInstance = connectionManager.CreateEmbeddedObjectInstance("SMS_Category_LocalizedProperties");
                embeddedObjectInstance["CategoryInstanceName"].StringValue = Name;
                embeddedObjectInstance["LocaleID"].IntegerValue            = 0;
                list.Add(embeddedObjectInstance);
                instance.SetArrayItems("LocalizedInformation", list);
                try
                {
                    instance.Put();
                    instance.Get();
                }
                catch (SmsQueryException ex)
                {
                    ManagementException mgmtException = ex.InnerException as ManagementException;
                    Exception.Add(new SystemException(mgmtException.ErrorInformation["Description"].ToString()));
                    return(false);
                }

                categoryObject = instance;
            }

            return(true);
        }
예제 #2
0
        public static void DeploySettings(string collectionId)
        {
            try
            {
                IResultObject collSettings = null;

                var wmiQuery = $"SELECT * FROM SMS_CollectionSettings WHERE CollectionID='{collectionId}'";
                var result   = Globals.Sccm.QueryProcessor.ExecuteQuery(wmiQuery) as WqlQueryResultsObject;

                foreach (IResultObject coll in result)
                {
                    collSettings = coll;
                    break;
                }

                if (collSettings == null)
                {
                    collSettings = Globals.Sccm.CreateInstance("SMS_CollectionSettings");
                    collSettings["CollectionID"].StringValue = collectionId;
                    collSettings["LocaleID"].IntegerValue    = Thread.CurrentThread.CurrentUICulture.LCID;
                }
                else
                {
                    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);
                    }
                }

                var settingsChunks = SettingsUtils.SettingsToString(Globals.Settings).Chunk(3000);

                var varCount = 0;

                foreach (var chunk in settingsChunks)
                {
                    var newVar = Globals.Sccm.CreateEmbeddedObjectInstance("SMS_CollectionVariable");

                    newVar["Name"].StringValue  = $"DPLSCH{varCount++:00}";
                    newVar["Value"].StringValue = chunk;

                    newList.Add(newVar);
                }

                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);
            }
        }