From 0e20a7691cb219a06e4e1ba314d29d1d286c879c Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Wed, 14 Feb 2018 14:26:03 +0100 Subject: [PATCH 01/10] Add files via upload --- ConfigMgrWebService/CMCollectionAdvanced.cs | 34 ++++++++++++++++++ ConfigMgrWebService/CMNode.cs | 40 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 ConfigMgrWebService/CMCollectionAdvanced.cs create mode 100644 ConfigMgrWebService/CMNode.cs diff --git a/ConfigMgrWebService/CMCollectionAdvanced.cs b/ConfigMgrWebService/CMCollectionAdvanced.cs new file mode 100644 index 0000000..aca85fe --- /dev/null +++ b/ConfigMgrWebService/CMCollectionAdvanced.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace ConfigMgrWebService +{ + + public class CMCollectionVariables + { + public string Name { get; set; } + public string CollectionID { get; set; } + public List Variable { get; set; } + } + + public class CMCollectionAdvanced + { + public string Name { get; set; } + public string CollectionID { get; set; } + public List Variable { get; set; } + public System.Collections.ArrayList AdhesionRules { get; set; } + } + + public class CMVariablesSettings + { + public string CollectionID { get; set; } + public List Variable { get; set; } + } + + public class CMVariables + { + public string Name { get; set; } + public string Value { get; set; } + } + +} \ No newline at end of file diff --git a/ConfigMgrWebService/CMNode.cs b/ConfigMgrWebService/CMNode.cs new file mode 100644 index 0000000..e6791e2 --- /dev/null +++ b/ConfigMgrWebService/CMNode.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; + +namespace ConfigMgrWebService +{ + public enum CMNodeObjectType + { + SMS_Package = 2, + SMS_Advertisement = 3, + SMS_Query = 7, + SMS_Report = 8, + SMS_MeteredProductRule = 9, + SMS_ConfigurationItem = 11, + SMS_OperatingSystemInstallPackage = 14, + SMS_StateMigration = 17, + SMS_ImagePackage = 18, + SMS_BootImagePackage = 19, + SMS_TaskSequencePackage = 20, + SMS_DeviceSettingPackage = 21, + SMS_DriverPackage = 23, + SMS_Driver = 25, + SMS_SoftwareUpdate = 1011, + SMS_ConfigurationItem_Baseline = 2011, + SMS_Collection_Device = 5000, + SMS_Collection_User = 5001, + SMS_ApplicationLatest = 6000 + } + + public class CMNode + { + public string Name { get; set; } + public string ContainerNodeID { get; set; } + public List MemberID { get; set; } + public List MemberGuid { get; set; } + public List InstanceKey { get; set; } + public string ParentContainerNodeID { get; set; } + public string FolderGuid { get; set; } + public string Path { get; set; } + } + +} \ No newline at end of file From 4c356df93a488b270a4bbc3ad596c4613d6c75fb Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Wed, 14 Feb 2018 14:33:17 +0100 Subject: [PATCH 02/10] Update ConfigMgrWebService.csproj --- ConfigMgrWebService/ConfigMgrWebService.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ConfigMgrWebService/ConfigMgrWebService.csproj b/ConfigMgrWebService/ConfigMgrWebService.csproj index caa1d01..0ed5763 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.csproj +++ b/ConfigMgrWebService/ConfigMgrWebService.csproj @@ -59,6 +59,7 @@ + @@ -148,4 +149,4 @@ --> - \ No newline at end of file + From a8970dd93c3a3095aad39c7a22e24174f9fa968b Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Wed, 14 Feb 2018 14:35:23 +0100 Subject: [PATCH 03/10] Update ConfigMgrWebService.asmx.cs --- .../ConfigMgrWebService.asmx.cs | 252 +++++++++++++++++- 1 file changed, 251 insertions(+), 1 deletion(-) diff --git a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs index b2e352e..883b509 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs +++ b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs @@ -975,6 +975,256 @@ public List GetCMDeviceCollections(string secret, string filter = return collectionList; } + [WebMethod(Description = "Get collection variable for filter device collection or all collections")] + public List GetCMCollectionVariableByName(string secret, CMCollectionType collectiontype, string[] filter = null) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + //' Construct list object + List collectionList = new List(); + + //' Validate secret key + if (secret == secretKey) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + + string collectionQuery = string.Empty; + string collectionsettingsQuery = string.Empty; + + if (filter == null || filter.All(item => string.IsNullOrEmpty(item))) + { + collectionQuery = String.Format("SELECT * FROM SMS_Collection WHERE CollectionType='{0:D}'", collectiontype); + } + else + { + collectionQuery = String.Format("SELECT * FROM SMS_Collection WHERE CollectionType='{0:D}' AND Name LIKE '%{1}%'", collectiontype, string.Join("%' OR Name LIKE '%", filter)); + } + + IResultObject tmpcollections = connection.QueryProcessor.ExecuteQuery(collectionQuery); + + List collectionIDfilter = new List(); + foreach (IResultObject tmpcollection in tmpcollections) + { + CMCollectionVariables tmpobj = new CMCollectionVariables + { + Name = tmpcollection["Name"].StringValue, + CollectionID = tmpcollection["CollectionID"].StringValue + }; + collectionList.Add(tmpobj); + collectionIDfilter.Add(tmpobj.CollectionID); + //collectionIDfilter.Add(tmpcollection["CollectionID"].StringValue); + + } + + if (collectionIDfilter != null || collectionIDfilter.All(item => string.IsNullOrEmpty(item))) + { + collectionsettingsQuery = String.Format("SELECT * FROM SMS_CollectionSettings WHERE CollectionID IN ('{0}')", string.Join("','", collectionIDfilter)); + IResultObject collectionsSettings = connection.QueryProcessor.ExecuteQuery(collectionsettingsQuery); + foreach (IResultObject collectionsettings in collectionsSettings) + { + collectionsettings.Get(); + List allvariables = new List(); + if (collectionsettings["CollectionVariables"].ObjectValue != null) + { + foreach (IResultObject varobject in collectionsettings.GetArrayItems("CollectionVariables")) + { + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } + } + + foreach (CMCollectionVariables collInList in collectionList) + { + if (collInList.CollectionID == collectionsettings["CollectionID"].StringValue) + { + collInList.Variable = allvariables; + } + } + + } + } + + } + + MethodEnd(method); + return collectionList; + } + + [WebMethod(Description = "Get collection variable for filter device collection or all collections")] + public List GetCMCollectionVariableByID(string secret, string[] filter = null) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + //' Construct list object + List collectionList = new List(); + + //' Validate secret key + if (secret == secretKey) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + + string collectionsettingsQuery = string.Empty; + + if (filter == null || filter.All(item => string.IsNullOrEmpty(item))) + { + collectionsettingsQuery = "SELECT * FROM SMS_CollectionSettings"; + } + else + { + collectionsettingsQuery = String.Format("SELECT * FROM SMS_CollectionSettings WHERE CollectionID IN ('{0}')", string.Join("','", filter)); + } + + IResultObject tmpsettings = connection.QueryProcessor.ExecuteQuery(collectionsettingsQuery); + + foreach (IResultObject tmpsetting in tmpsettings) + { + tmpsetting.Get(); + List allvariables = new List(); + if (tmpsetting["CollectionVariables"].ObjectValue != null) + { + foreach (IResultObject varobject in tmpsetting.GetArrayItems("CollectionVariables")) + { + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } + } + + CMVariablesSettings collectionsproperties = new CMVariablesSettings + { + CollectionID = tmpsetting["CollectionID"].StringValue, + Variable = allvariables + }; + collectionList.Add(collectionsproperties); + } + + } + + MethodEnd(method); + return collectionList; + } + + [WebMethod(Description = "Get SCCM Console device collection Folder Structure")] + public List GetCMNodeObjects(string secret, CMNodeObjectType objecttype = CMNodeObjectType.SMS_Collection_Device) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + //' Construct list object + List folderList = new List(); + + //' Validate secret key + if (secret == secretKey) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + + //' folders query + string deviceFolderNodesQuery = String.Format("Select * From SMS_ObjectContainerNode Where ObjectType='{0:D}'", objecttype); + string deviceFolderItemsQuery = String.Format("Select * From SMS_ObjectContainerItem Where ObjectType='{0:D}'", objecttype); + + // + IResultObject foldernodes = connection.QueryProcessor.ExecuteQuery(deviceFolderNodesQuery); + IResultObject tmpfolderitems = connection.QueryProcessor.ExecuteQuery(deviceFolderItemsQuery); + + ArrayList folderitems = new ArrayList(); + foreach (IResultObject tmpfolderitem in tmpfolderitems) + { + folderitems.Add(tmpfolderitem); + } + + if (folderList != null) + { + foreach (IResultObject foldernode in foldernodes) + { + List MemberIDTmpArray = new List(); + List MemberGuidTmpArray = new List(); + List InstanceKeyTmpArray = new List(); + + foreach (IResultObject folderitem in folderitems) + { + if (folderitem["ContainerNodeID"].StringValue == foldernode["ContainerNodeID"].StringValue) + { + MemberIDTmpArray.Add(folderitem["MemberID"].StringValue); + MemberGuidTmpArray.Add(folderitem["MemberGuid"].StringValue); + InstanceKeyTmpArray.Add(folderitem["InstanceKey"].StringValue); + } + } + + CMNode tmpfolder = new CMNode() + { + Name = foldernode["Name"].StringValue, + ContainerNodeID = foldernode["ContainerNodeID"].StringValue, + MemberID = MemberIDTmpArray, + MemberGuid = MemberGuidTmpArray, + InstanceKey = InstanceKeyTmpArray, + ParentContainerNodeID = foldernode["ParentContainerNodeID"].StringValue, + FolderGuid = foldernode["FolderGuid"].StringValue + }; + folderList.Add(tmpfolder); + } + + foreach (CMNode folder in folderList) + { + if (folder.ParentContainerNodeID != "0") + { + CMNode ParentContainerProperties = new CMNode(); + foreach (CMNode f in folderList) + { + if (f.ContainerNodeID == folder.ParentContainerNodeID) + { + ParentContainerProperties = f; + } + } + + bool ParentContainer = true; + while (ParentContainer == true) + { + folder.Path = (ParentContainerProperties.Name + "\\" + folder.Path); + if (ParentContainerProperties.ParentContainerNodeID != "0") + { + foreach (CMNode f1 in folderList) + { + if (f1.ContainerNodeID == ParentContainerProperties.ParentContainerNodeID) + { + ParentContainerProperties = f1; + } + } + } + else + { + ParentContainer = false; + folder.Path = ("Root\\" + folder.Path + folder.Name); + } + } + } + else + { + folder.Path = ("Root\\" + folder.Name); + } + } + + } + } + MethodEnd(method); + return folderList; + } + + [WebMethod(Description = "Update membership of a specific collection")] public bool UpdateCMCollectionMembership(string secret, string collectionId) { @@ -3976,4 +4226,4 @@ public static void WriteEventLog(string logEntry, EventLogEntryType entryType) } } } -} \ No newline at end of file +} From 64920723029ec2aaf8706f9312a1d0726ee01601 Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Wed, 14 Feb 2018 14:42:20 +0100 Subject: [PATCH 04/10] Update CMNode.cs --- ConfigMgrWebService/CMNode.cs | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/ConfigMgrWebService/CMNode.cs b/ConfigMgrWebService/CMNode.cs index e6791e2..824df4b 100644 --- a/ConfigMgrWebService/CMNode.cs +++ b/ConfigMgrWebService/CMNode.cs @@ -2,39 +2,39 @@ namespace ConfigMgrWebService { - public enum CMNodeObjectType - { - SMS_Package = 2, - SMS_Advertisement = 3, - SMS_Query = 7, - SMS_Report = 8, - SMS_MeteredProductRule = 9, - SMS_ConfigurationItem = 11, - SMS_OperatingSystemInstallPackage = 14, - SMS_StateMigration = 17, - SMS_ImagePackage = 18, - SMS_BootImagePackage = 19, - SMS_TaskSequencePackage = 20, - SMS_DeviceSettingPackage = 21, - SMS_DriverPackage = 23, - SMS_Driver = 25, - SMS_SoftwareUpdate = 1011, - SMS_ConfigurationItem_Baseline = 2011, - SMS_Collection_Device = 5000, - SMS_Collection_User = 5001, - SMS_ApplicationLatest = 6000 - } + public enum CMNodeObjectType + { + SMS_Package = 2, + SMS_Advertisement = 3, + SMS_Query = 7, + SMS_Report = 8, + SMS_MeteredProductRule = 9, + SMS_ConfigurationItem = 11, + SMS_OperatingSystemInstallPackage = 14, + SMS_StateMigration = 17, + SMS_ImagePackage = 18, + SMS_BootImagePackage = 19, + SMS_TaskSequencePackage = 20, + SMS_DeviceSettingPackage = 21, + SMS_DriverPackage = 23, + SMS_Driver = 25, + SMS_SoftwareUpdate = 1011, + SMS_ConfigurationItem_Baseline = 2011, + SMS_Collection_Device = 5000, + SMS_Collection_User = 5001, + SMS_ApplicationLatest = 6000 + } - public class CMNode - { - public string Name { get; set; } - public string ContainerNodeID { get; set; } - public List MemberID { get; set; } - public List MemberGuid { get; set; } - public List InstanceKey { get; set; } - public string ParentContainerNodeID { get; set; } + public class CMNode + { + public string Name { get; set; } + public string ContainerNodeID { get; set; } + public List MemberID { get; set; } + public List MemberGuid { get; set; } + public List InstanceKey { get; set; } + public string ParentContainerNodeID { get; set; } public string FolderGuid { get; set; } public string Path { get; set; } } -} \ No newline at end of file +} From e2ee8d9eef1b8206af72e419ef0affd97d9e49cd Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Wed, 14 Feb 2018 19:00:29 +0100 Subject: [PATCH 05/10] Update ConfigMgrWebService.asmx.cs --- ConfigMgrWebService/ConfigMgrWebService.asmx.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs index 883b509..641c3d4 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs +++ b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs @@ -975,7 +975,7 @@ public List GetCMDeviceCollections(string secret, string filter = return collectionList; } - [WebMethod(Description = "Get collection variable for filter device collection or all collections")] + [WebMethod(Description = "Get collection variable for filtered device collection or all collections")] public List GetCMCollectionVariableByName(string secret, CMCollectionType collectiontype, string[] filter = null) { MethodBase method = MethodBase.GetCurrentMethod(); @@ -1057,7 +1057,7 @@ public List GetCMCollectionVariableByName(string secret, return collectionList; } - [WebMethod(Description = "Get collection variable for filter device collection or all collections")] + [WebMethod(Description = "Get collection variable for filtered device collection or all collections")] public List GetCMCollectionVariableByID(string secret, string[] filter = null) { MethodBase method = MethodBase.GetCurrentMethod(); @@ -1117,7 +1117,7 @@ public List GetCMCollectionVariableByID(string secret, stri return collectionList; } - [WebMethod(Description = "Get SCCM Console device collection Folder Structure")] + [WebMethod(Description = "Get all object in sccm console node.")] public List GetCMNodeObjects(string secret, CMNodeObjectType objecttype = CMNodeObjectType.SMS_Collection_Device) { MethodBase method = MethodBase.GetCurrentMethod(); From 85f40a63f2a798c518c8354c405e8080294a6c3a Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Thu, 15 Feb 2018 20:50:18 +0100 Subject: [PATCH 06/10] Update ConfigMgrWebService.asmx.cs --- .../ConfigMgrWebService.asmx.cs | 291 ++++++++++++++++++ 1 file changed, 291 insertions(+) diff --git a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs index 641c3d4..452e25c 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs +++ b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs @@ -19,6 +19,7 @@ using System.Net; using System.Security; using System.Runtime.InteropServices; +using System.Xml.Serialization; namespace ConfigMgrWebService { @@ -1117,6 +1118,296 @@ public List GetCMCollectionVariableByID(string secret, stri return collectionList; } + [WebMethod(Description = "Get collection variable and adhesion rule for filtered collection or all collections")] + [XmlInclude(typeof(CMQueryRule))] + [XmlInclude(typeof(CMDirectRule))] + [XmlInclude(typeof(CMIncludeRule))] + [XmlInclude(typeof(CMExcludeRule))] + public List GetCMCollectionAdvancedByName(string secret, CMCollectionType collectiontype, string[] filter = null) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + //' Construct list object + List collectionList = new List(); + + //' Validate secret key + if (secret == secretKey) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + + string collectionQuery = string.Empty; + string collectionsettingsQuery = string.Empty; + + if (filter == null || filter.All(item => string.IsNullOrEmpty(item))) + { + collectionQuery = String.Format("SELECT * FROM SMS_Collection WHERE CollectionType='{0:D}'", collectiontype); + } + else + { + collectionQuery = String.Format("SELECT * FROM SMS_Collection WHERE CollectionType='{0:D}' AND Name LIKE '%{1}%'", collectiontype, string.Join("%' OR Name LIKE '%", filter)); + } + + IResultObject tmpcollections = connection.QueryProcessor.ExecuteQuery(collectionQuery); + + List collectionIDfilter = new List(); + ArrayList tmpcollectionList = new ArrayList(); + foreach (IResultObject tmpcollection in tmpcollections) + { + tmpcollectionList.Add(tmpcollection); + collectionIDfilter.Add(tmpcollection["CollectionID"].StringValue); + } + + if (collectionIDfilter != null || collectionIDfilter.All(item => string.IsNullOrEmpty(item))) + { + collectionsettingsQuery = String.Format("SELECT * FROM SMS_CollectionSettings WHERE CollectionID IN ('{0}')", string.Join("','", collectionIDfilter)); + IResultObject collectionsSettings = connection.QueryProcessor.ExecuteQuery(collectionsettingsQuery); + List collectionssettings = new List(); + foreach (IResultObject collectionsettings in collectionsSettings) + { + collectionsettings.Get(); + List allvariables = new List(); + if (collectionsettings["CollectionVariables"].ObjectValue != null) + { + + foreach (IResultObject varobject in collectionsettings.GetArrayItems("CollectionVariables")) + { + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } + } + + CMVariablesSettings collectionsproperties = new CMVariablesSettings + { + CollectionID = collectionsettings["CollectionID"].StringValue, + Variable = allvariables + }; + collectionssettings.Add(collectionsproperties); + } + + foreach (IResultObject tmpcollectionlist in tmpcollectionList) + { + tmpcollectionlist.Get(); + ArrayList collectionrulelist = new ArrayList(); + if (tmpcollectionlist["CollectionRules"].ObjectValue != null) + { + foreach (IResultObject collectionrule in tmpcollectionlist.GetArrayItems("CollectionRules")) + { + if (collectionrule["__CLASS"].StringValue == "SMS_CollectionRuleQuery") + { + CMQueryRule tmpcollectionrule = new CMQueryRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + QueryID = collectionrule["QueryID"].StringValue, + QueryExpression = collectionrule["QueryExpression"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + else if (collectionrule["__CLASS"].StringValue == "SMS_CollectionRuleDirect") + { + CMDirectRule tmpcollectionrule = new CMDirectRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + ResourceClassName = collectionrule["ResourceClassName"].StringValue, + ResourceID = collectionrule["ResourceID"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + else if (collectionrule["__CLASS"].StringValue == "SMS_CollectionRuleIncludeCollection") + { + CMIncludeRule tmpcollectionrule = new CMIncludeRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + IncludeCollectionID = collectionrule["IncludeCollectionID"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + else + { + CMExcludeRule tmpcollectionrule = new CMExcludeRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + ExcludeCollectionID = collectionrule["ExcludeCollectionID"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + } + } + + foreach (CMVariablesSettings collsetting in collectionssettings) + { + if (collsetting.CollectionID == tmpcollectionlist["CollectionID"].StringValue) + { + CMCollectionAdvanced tmpcollectionadvanced = new CMCollectionAdvanced + { + Name = tmpcollectionlist["Name"].StringValue, + CollectionID = tmpcollectionlist["CollectionID"].StringValue, + Variable = collsetting.Variable, + AdhesionRules = collectionrulelist + }; + collectionList.Add(tmpcollectionadvanced); + } + } + } + } + } + + MethodEnd(method); + return collectionList; + } + + [WebMethod(Description = "Get collection variable and adhesion rule for filtered collection or all collections")] + [XmlInclude(typeof(CMQueryRule))] + [XmlInclude(typeof(CMDirectRule))] + [XmlInclude(typeof(CMIncludeRule))] + [XmlInclude(typeof(CMExcludeRule))] + public List GetCMCollectionAdvancedByID(string secret, CMCollectionType collectiontype, string[] filter = null) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + //' Construct list object + List collectionList = new List(); + + //' Validate secret key + if (secret == secretKey) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + + string collectionQuery = string.Empty; + string collectionsettingsQuery = string.Empty; + + if (filter == null || filter.All(item => string.IsNullOrEmpty(item))) + { + collectionQuery = String.Format("SELECT * FROM SMS_Collection WHERE CollectionType='{0:D}'", collectiontype); + collectionsettingsQuery = "SELECT * FROM SMS_CollectionSettings"; + } + else + { + collectionQuery = String.Format("SELECT * FROM SMS_Collection WHERE CollectionType='{0:D}' AND CollectionID IN ('{1}')", collectiontype, string.Join("','", filter)); + collectionsettingsQuery = String.Format("SELECT * FROM SMS_CollectionSettings WHERE CollectionID IN ('{0}')", string.Join("','", filter)); + } + + IResultObject collections = connection.QueryProcessor.ExecuteQuery(collectionQuery); + IResultObject tmpsettings = connection.QueryProcessor.ExecuteQuery(collectionsettingsQuery); + + List collectionssettings = new List(); + + foreach (IResultObject tmpsetting in tmpsettings) + { + tmpsetting.Get(); + List allvariables = new List(); + if (tmpsetting["CollectionVariables"].ObjectValue != null) + { + foreach (IResultObject varobject in tmpsetting.GetArrayItems("CollectionVariables")) + { + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } + } + + CMVariablesSettings collectionsproperties = new CMVariablesSettings + { + CollectionID = tmpsetting["CollectionID"].StringValue, + Variable = allvariables + }; + collectionssettings.Add(collectionsproperties); + } + + foreach (IResultObject collection in collections) + { + collection.Get(); + List variable = new List(); + foreach (CMVariablesSettings collectionsetting in collectionssettings) + { + if (collectionsetting.CollectionID == collection["CollectionID"].StringValue) + { + variable = collectionsetting.Variable; + } + } + + ArrayList collectionrulelist = new ArrayList(); + if (collection["CollectionRules"].ObjectValue != null) + { + foreach (IResultObject collectionrule in collection.GetArrayItems("CollectionRules")) + { + if (collectionrule["__CLASS"].StringValue == "SMS_CollectionRuleQuery") + { + CMQueryRule tmpcollectionrule = new CMQueryRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + QueryID = collectionrule["QueryID"].StringValue, + QueryExpression = collectionrule["QueryExpression"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + else if (collectionrule["__CLASS"].StringValue == "SMS_CollectionRuleDirect") + { + CMDirectRule tmpcollectionrule = new CMDirectRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + ResourceClassName = collectionrule["ResourceClassName"].StringValue, + ResourceID = collectionrule["ResourceID"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + else if (collectionrule["__CLASS"].StringValue == "SMS_CollectionRuleIncludeCollection") + { + CMIncludeRule tmpcollectionrule = new CMIncludeRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + IncludeCollectionID = collectionrule["IncludeCollectionID"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + else + { + CMExcludeRule tmpcollectionrule = new CMExcludeRule + { + RuleType = collectionrule["__CLASS"].StringValue, + RuleName = collectionrule["RuleName"].StringValue, + ExcludeCollectionID = collectionrule["ExcludeCollectionID"].StringValue + }; + collectionrulelist.Add(tmpcollectionrule); + } + } + } + + CMCollectionAdvanced collectioninfos = new CMCollectionAdvanced + { + Name = collection["Name"].StringValue, + CollectionID = collection["CollectionID"].StringValue, + Variable = variable, + AdhesionRules = collectionrulelist + }; + collectionList.Add(collectioninfos); + + } + } + + MethodEnd(method); + return collectionList; + } + [WebMethod(Description = "Get all object in sccm console node.")] public List GetCMNodeObjects(string secret, CMNodeObjectType objecttype = CMNodeObjectType.SMS_Collection_Device) { From 4018f1273696e869f9929ed26c86df9d1d75709d Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Thu, 15 Feb 2018 20:51:09 +0100 Subject: [PATCH 07/10] Update CMCollectionAdvanced.cs --- ConfigMgrWebService/CMCollectionAdvanced.cs | 62 ++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/ConfigMgrWebService/CMCollectionAdvanced.cs b/ConfigMgrWebService/CMCollectionAdvanced.cs index aca85fe..32cdb05 100644 --- a/ConfigMgrWebService/CMCollectionAdvanced.cs +++ b/ConfigMgrWebService/CMCollectionAdvanced.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Runtime.Serialization; namespace ConfigMgrWebService @@ -31,4 +31,62 @@ public class CMVariables public string Value { get; set; } } -} \ No newline at end of file + [DataContract(Name = "QueryRule")] + public class CMQueryRule + { + [DataMember] + public string RuleName { get; set; } + + [DataMember] + public string RuleType { get; set; } + + [DataMember] + public string QueryID { get; set; } + + [DataMember] + public string QueryExpression { get; set; } + + } + + [DataContract(Name = "DirectRule")] + public class CMDirectRule + { + [DataMember] + public string RuleName { get; set; } + + [DataMember] + public string RuleType { get; set; } + + [DataMember] + public string ResourceClassName { get; set; } + + [DataMember] + public string ResourceID { get; set; } + } + + [DataContract(Name = "IncludeRule")] + public class CMIncludeRule + { + [DataMember] + public string RuleName { get; set; } + + [DataMember] + public string RuleType { get; set; } + + [DataMember] + public string IncludeCollectionID { get; set; } + } + + [DataContract(Name = "ExcludeRule")] + public class CMExcludeRule + { + [DataMember] + public string RuleName { get; set; } + + [DataMember] + public string RuleType { get; set; } + + [DataMember] + public string ExcludeCollectionID { get; set; } + } +} From c07fc5cb6f3ad7d9e99b3d1f0f7ff5cfe8849221 Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Thu, 15 Feb 2018 20:53:50 +0100 Subject: [PATCH 08/10] Update ConfigMgrWebService.asmx.cs --- ConfigMgrWebService/ConfigMgrWebService.asmx.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs index 452e25c..a06c214 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs +++ b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs @@ -1016,8 +1016,6 @@ public List GetCMCollectionVariableByName(string secret, }; collectionList.Add(tmpobj); collectionIDfilter.Add(tmpobj.CollectionID); - //collectionIDfilter.Add(tmpcollection["CollectionID"].StringValue); - } if (collectionIDfilter != null || collectionIDfilter.All(item => string.IsNullOrEmpty(item))) From 859457bda26ece16d099a9704ebc8df21ee80b03 Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Sun, 25 Feb 2018 21:35:31 +0100 Subject: [PATCH 09/10] Add files via upload --- ConfigMgrWebService/CMDevice.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ConfigMgrWebService/CMDevice.cs diff --git a/ConfigMgrWebService/CMDevice.cs b/ConfigMgrWebService/CMDevice.cs new file mode 100644 index 0000000..ccd9e80 --- /dev/null +++ b/ConfigMgrWebService/CMDevice.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace ConfigMgrWebService +{ + public class CMDevice + { + public string Name { get; set; } + public List Variable { get; set; } + } + + public class CMDeviceByID + { + public string ResourceID { get; set; } + public List Variable { get; set; } + } + + public class CMDeviceVariable + { + public string Name { get; set; } + public string Value { get; set; } + } +} \ No newline at end of file From 78ac63edd12a69712740bf728c443143ecfcce50 Mon Sep 17 00:00:00 2001 From: GlenR2D2 <36387833+GlenR2D2@users.noreply.github.com> Date: Sun, 25 Feb 2018 21:38:26 +0100 Subject: [PATCH 10/10] Update ConfigMgrWebService.asmx.cs --- .../ConfigMgrWebService.asmx.cs | 264 +++++++++++++----- 1 file changed, 189 insertions(+), 75 deletions(-) diff --git a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs index a06c214..2c42fa0 100644 --- a/ConfigMgrWebService/ConfigMgrWebService.asmx.cs +++ b/ConfigMgrWebService/ConfigMgrWebService.asmx.cs @@ -976,7 +976,111 @@ public List GetCMDeviceCollections(string secret, string filter = return collectionList; } - [WebMethod(Description = "Get collection variable for filtered device collection or all collections")] + [WebMethod(Description = "Get collection variable for device by Name")] + public CMDevice GetCMDeviceVariableByName(string secret, string computername = null) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + CMDevice computerproperties = new CMDevice(); + + //' Validate secret key + if (secret == secretKey) + { + if (computername != null) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + string computerquery = string.Empty; + computerquery = String.Format("SELECT * FROM SMS_R_SYSTEM WHERE Name='{0}'", computername); + IResultObject computerinfos = connection.QueryProcessor.ExecuteQuery(computerquery); + + foreach (IResultObject computerinfo in computerinfos) + { + if (computerinfo["ResourceID"].StringValue != null) + { + string computervarquery = string.Empty; + computervarquery = String.Format("SELECT * FROM SMS_MachineSettings WHERE ResourceID='{0}'", computerinfo["ResourceID"].StringValue); + IResultObject computervarinfos = connection.QueryProcessor.ExecuteQuery(computervarquery); + foreach (IResultObject computervarinfo in computervarinfos) + { + computervarinfo.Get(); + if (computervarinfo["MachineVariables"].ObjectValue != null) + { + List variablelist = new List(); + foreach (IResultObject computervariable in computervarinfo.GetArrayItems("MachineVariables")) + { + if (computervariable["IsMasked"].BooleanValue == false) + { + CMDeviceVariable devicevariable = new CMDeviceVariable + { + Name = computervariable["Name"].StringValue, + Value = computervariable["Value"].StringValue + }; + variablelist.Add(devicevariable); + } + } + computerproperties.Name = computerinfo["Name"].StringValue; + computerproperties.Variable = variablelist; + } + } + } + } + } + } + MethodEnd(method); + return computerproperties; + } + + [WebMethod(Description = "Get collection variable for device by ID")] + public CMDeviceByID GetCMDeviceVariableByID(string secret, string resourceid = null) + { + MethodBase method = MethodBase.GetCurrentMethod(); + MethodBegin(method); + + CMDeviceByID computerproperties = new CMDeviceByID(); + + //' Validate secret key + if (secret == secretKey) + { + if (resourceid != null) + { + //' Connect to SMS Provider + SmsProvider smsProvider = new SmsProvider(); + WqlConnectionManager connection = smsProvider.Connect(siteServer); + string computervarquery = string.Empty; + computervarquery = String.Format("SELECT * FROM SMS_MachineSettings WHERE ResourceID='{0}'", resourceid); + IResultObject computervarinfos = connection.QueryProcessor.ExecuteQuery(computervarquery); + foreach (IResultObject computervarinfo in computervarinfos) + { + computervarinfo.Get(); + if (computervarinfo["MachineVariables"].ObjectValue != null) + { + List variablelist = new List(); + foreach (IResultObject computervariable in computervarinfo.GetArrayItems("MachineVariables")) + { + if (computervariable["IsMasked"].BooleanValue == false) + { + CMDeviceVariable devicevariable = new CMDeviceVariable + { + Name = computervariable["Name"].StringValue, + Value = computervariable["Value"].StringValue + }; + variablelist.Add(devicevariable); + } + } + computerproperties.ResourceID = computervarinfo["ResourceID"].StringValue; + computerproperties.Variable = variablelist; + } + } + } + } + MethodEnd(method); + return computerproperties; + } + + [WebMethod(Description = "Get collection variable for filter collection or all collections")] public List GetCMCollectionVariableByName(string secret, CMCollectionType collectiontype, string[] filter = null) { MethodBase method = MethodBase.GetCurrentMethod(); @@ -1016,6 +1120,7 @@ public List GetCMCollectionVariableByName(string secret, }; collectionList.Add(tmpobj); collectionIDfilter.Add(tmpobj.CollectionID); + } if (collectionIDfilter != null || collectionIDfilter.All(item => string.IsNullOrEmpty(item))) @@ -1030,12 +1135,15 @@ public List GetCMCollectionVariableByName(string secret, { foreach (IResultObject varobject in collectionsettings.GetArrayItems("CollectionVariables")) { - CMVariables tmpvar = new CMVariables + if (varobject["IsMasked"].BooleanValue == false) { - Name = varobject["Name"].StringValue, - Value = varobject["Value"].StringValue - }; - allvariables.Add(tmpvar); + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } } } @@ -1056,7 +1164,7 @@ public List GetCMCollectionVariableByName(string secret, return collectionList; } - [WebMethod(Description = "Get collection variable for filtered device collection or all collections")] + [WebMethod(Description = "Get collection variable for filter collection or all collections")] public List GetCMCollectionVariableByID(string secret, string[] filter = null) { MethodBase method = MethodBase.GetCurrentMethod(); @@ -1093,12 +1201,15 @@ public List GetCMCollectionVariableByID(string secret, stri { foreach (IResultObject varobject in tmpsetting.GetArrayItems("CollectionVariables")) { - CMVariables tmpvar = new CMVariables + if (varobject["IsMasked"].BooleanValue == false) { - Name = varobject["Name"].StringValue, - Value = varobject["Value"].StringValue - }; - allvariables.Add(tmpvar); + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } } } @@ -1172,12 +1283,15 @@ public List GetCMCollectionAdvancedByName(string secret, C foreach (IResultObject varobject in collectionsettings.GetArrayItems("CollectionVariables")) { - CMVariables tmpvar = new CMVariables + if (varobject["Ismasked"].BooleanValue == false) { - Name = varobject["Name"].StringValue, - Value = varobject["Value"].StringValue - }; - allvariables.Add(tmpvar); + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } } } @@ -1311,12 +1425,15 @@ public List GetCMCollectionAdvancedByID(string secret, CMC { foreach (IResultObject varobject in tmpsetting.GetArrayItems("CollectionVariables")) { - CMVariables tmpvar = new CMVariables + if (varobject["IsMasked"].BooleanValue == false) { - Name = varobject["Name"].StringValue, - Value = varobject["Value"].StringValue - }; - allvariables.Add(tmpvar); + CMVariables tmpvar = new CMVariables + { + Name = varobject["Name"].StringValue, + Value = varobject["Value"].StringValue + }; + allvariables.Add(tmpvar); + } } } @@ -1406,7 +1523,7 @@ public List GetCMCollectionAdvancedByID(string secret, CMC return collectionList; } - [WebMethod(Description = "Get all object in sccm console node.")] + [WebMethod(Description = "Get SCCM Console Node objects")] public List GetCMNodeObjects(string secret, CMNodeObjectType objecttype = CMNodeObjectType.SMS_Collection_Device) { MethodBase method = MethodBase.GetCurrentMethod(); @@ -1436,77 +1553,73 @@ public List GetCMNodeObjects(string secret, CMNodeObjectType objecttype folderitems.Add(tmpfolderitem); } - if (folderList != null) + foreach (IResultObject foldernode in foldernodes) { - foreach (IResultObject foldernode in foldernodes) - { - List MemberIDTmpArray = new List(); - List MemberGuidTmpArray = new List(); - List InstanceKeyTmpArray = new List(); + List MemberIDTmpArray = new List(); + List MemberGuidTmpArray = new List(); + List InstanceKeyTmpArray = new List(); - foreach (IResultObject folderitem in folderitems) + foreach (IResultObject folderitem in folderitems) + { + if (folderitem["ContainerNodeID"].StringValue == foldernode["ContainerNodeID"].StringValue) { - if (folderitem["ContainerNodeID"].StringValue == foldernode["ContainerNodeID"].StringValue) - { - MemberIDTmpArray.Add(folderitem["MemberID"].StringValue); - MemberGuidTmpArray.Add(folderitem["MemberGuid"].StringValue); - InstanceKeyTmpArray.Add(folderitem["InstanceKey"].StringValue); - } + MemberIDTmpArray.Add(folderitem["MemberID"].StringValue); + MemberGuidTmpArray.Add(folderitem["MemberGuid"].StringValue); + InstanceKeyTmpArray.Add(folderitem["InstanceKey"].StringValue); } - - CMNode tmpfolder = new CMNode() - { - Name = foldernode["Name"].StringValue, - ContainerNodeID = foldernode["ContainerNodeID"].StringValue, - MemberID = MemberIDTmpArray, - MemberGuid = MemberGuidTmpArray, - InstanceKey = InstanceKeyTmpArray, - ParentContainerNodeID = foldernode["ParentContainerNodeID"].StringValue, - FolderGuid = foldernode["FolderGuid"].StringValue - }; - folderList.Add(tmpfolder); } - foreach (CMNode folder in folderList) + CMNode tmpfolder = new CMNode() + { + Name = foldernode["Name"].StringValue, + ContainerNodeID = foldernode["ContainerNodeID"].StringValue, + MemberID = MemberIDTmpArray, + MemberGuid = MemberGuidTmpArray, + InstanceKey = InstanceKeyTmpArray, + ParentContainerNodeID = foldernode["ParentContainerNodeID"].StringValue, + FolderGuid = foldernode["FolderGuid"].StringValue + }; + folderList.Add(tmpfolder); + } + + foreach (CMNode folder in folderList) + { + if (folder.ParentContainerNodeID != "0") { - if (folder.ParentContainerNodeID != "0") + CMNode ParentContainerProperties = new CMNode(); + foreach (CMNode f in folderList) { - CMNode ParentContainerProperties = new CMNode(); - foreach (CMNode f in folderList) + if (f.ContainerNodeID == folder.ParentContainerNodeID) { - if (f.ContainerNodeID == folder.ParentContainerNodeID) - { - ParentContainerProperties = f; - } + ParentContainerProperties = f; } + } - bool ParentContainer = true; - while (ParentContainer == true) + bool ParentContainer = true; + while (ParentContainer == true) + { + folder.Path = (ParentContainerProperties.Name + "\\" + folder.Path); + if (ParentContainerProperties.ParentContainerNodeID != "0") { - folder.Path = (ParentContainerProperties.Name + "\\" + folder.Path); - if (ParentContainerProperties.ParentContainerNodeID != "0") + foreach (CMNode f1 in folderList) { - foreach (CMNode f1 in folderList) + if (f1.ContainerNodeID == ParentContainerProperties.ParentContainerNodeID) { - if (f1.ContainerNodeID == ParentContainerProperties.ParentContainerNodeID) - { - ParentContainerProperties = f1; - } + ParentContainerProperties = f1; } } - else - { - ParentContainer = false; - folder.Path = ("Root\\" + folder.Path + folder.Name); - } } - } - else - { - folder.Path = ("Root\\" + folder.Name); + else + { + ParentContainer = false; + folder.Path = ("Root\\" + folder.Path + folder.Name); + } } } - + else + { + folder.Path = ("Root\\" + folder.Name); + } } } MethodEnd(method); @@ -1514,6 +1627,7 @@ public List GetCMNodeObjects(string secret, CMNodeObjectType objecttype } + [WebMethod(Description = "Update membership of a specific collection")] public bool UpdateCMCollectionMembership(string secret, string collectionId) {