{"id":1823,"date":"2018-03-04T18:25:57","date_gmt":"2018-03-04T18:25:57","guid":{"rendered":"https:\/\/www.autoitconsulting.com\/site\/?page_id=1823"},"modified":"2025-07-26T14:32:36","modified_gmt":"2025-07-26T13:32:36","slug":"iresultobject-lazy-properties","status":"publish","type":"page","link":"https:\/\/www.autoitconsulting.com\/site\/sccm-sdk\/fundamentals\/iresultobject-lazy-properties\/","title":{"rendered":"IResultObject Lazy Properties"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p>Some Microsoft Configuration Manager (ConfigMgr) WMI classes make use of\u00a0<strong>lazy properties<\/strong>. These are properties that are not returned from <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc146276.aspx\" target=\"_blank\" rel=\"noopener\">WqlConnectionManager.ExecuteQuery()<\/a> by default in order to reduce the time taken for large queries to be processed.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Note<\/strong><\/p>\n\n\n\n<p>When using <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc146237.aspx\" target=\"_blank\" rel=\"noopener\">IResultObject.Get()<\/a>&nbsp;or <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.configurationmanagement.managementprovider.connectionmanagerbase.getinstance.aspx\">WqlConnectionManager.GetInstance()<\/a> the lazy properties&nbsp;<strong>are<\/strong> returned.<\/p>\n<\/blockquote>\n\n\n\n<p>Here is an extract of the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sccm\/develop\/reference\/core\/clients\/collections\/sms_collection-server-wmi-class\">SMS_Collection<\/a> class description on <a href=\"https:\/\/docs.microsoft.com\/en-us\/sccm\/develop\/reference\/core\/clients\/collections\/sms_collection-server-wmi-class\">MSDN<\/a>:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>CollectionID<\/strong><br>Data type: String<br>Access type: Read-only<br><span style=\"text-decoration: underline;\">Qualifiers: [<strong>key<\/strong>, read]<\/span><br>Unique auto-generated ID containing eight characters. The default value is &#8220;&#8221;.<br>The format of the collection ID is the site code that created the collection followed by a five-digit hexadecimal serial number, for example, &#8220;JAX0002C&#8221;. The default Configuration Manager collections, created during the installation, use the &#8220;SMS&#8221; prefix, for example, &#8220;SMS00001&#8221;.<\/p>\n\n\n\n<p><strong>CollectionRules<\/strong><br>Data type: SMS_CollectionRule Array<br>Access type: Read\/Write<br><span style=\"text-decoration: underline;\">Qualifiers: [<strong>lazy<\/strong>]<\/span><\/p>\n<\/blockquote>\n\n\n\n<p>The&nbsp;<strong>Qualifiers<\/strong> entry for each property is important as it shows the&nbsp;primary key (&#8216;<strong>key<\/strong>&#8216;) for the class and also which of the properties are lazy properties (&#8216;<strong>lazy<\/strong>&#8216;).<\/p>\n\n\n\n<p>Lazy properties are either set to&nbsp;<strong>null<\/strong> or blank after retrieving using&nbsp;ExecuteQuery(). If you are only reading properties of a class and you don&#8217;t require access to the lazy properties then there is no need to call Get()&nbsp;on them &#8211; and it is more efficient when working with large query sets. But you&nbsp;<strong>must<\/strong> call Get() or use GetInstance()&nbsp;in the following scenarios:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need to read the lazy property.<\/li>\n\n\n\n<li>You intend to write the object back to ConfigMgr with <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc146248.aspx\" target=\"_blank\" rel=\"noopener\">IResultObject.Put()<\/a><\/li>\n<\/ul>\n\n\n\n<p><strong>Writing an object that contains lazy properties back to SCCM without first retrieving those lazy properties will corrupt the object.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Examples and Downloads<\/h2>\n\n\n\n<p>The examples on this page can be downloaded from the <a href=\"https:\/\/github.com\/AutoItConsulting\/sccm-sdk-snippets\" target=\"_blank\" rel=\"noopener\">GitHub repo<\/a>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/AutoItConsulting\/sccm-sdk-snippets\/blob\/master\/src\/AutoIt.SCCM.SDK.Snippets\/Fundamentals\/LazyProperties.cs\" target=\"_blank\" rel=\"noopener\">LazyProperties.cs<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">IResultObject &#8211; Read Lazy Properties from SMS_Collection<\/h3>\n\n\n\n<p>This example uses ExecuteQuery to access a collection and then the&nbsp;<strong>Get<\/strong> method to get lazy properties&nbsp;<strong>CollectionRules<\/strong>.<\/p>\n\n\n\n<p>The rules are disposed using an extension method. See&nbsp;<a href=\"https:\/\/www.autoitconsulting.com\/site\/sccm-sdk\/fundamentals\/iresultobject-disposal\/\">IResultObject Disposal<\/a>&nbsp;\/ <strong>GetArrayItems<\/strong> for details.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 0 16px;font-size:0.8em;width:100%;text-align:left;background-color:#1E1E1E;font-style:italic;color:#D4D4D4\"><span style=\"border-bottom:1px solid rgba(234, 191, 191, 0.2)\">C#<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>public void LazyPropertyFromQuery(WqlConnectionManager connection)  \n{  \n    try  \n    {  \n        \/\/ Query the All Systems collection (this has two default rules)\n        using (IResultObject collections = connection.QueryProcessor.ExecuteQuery(\"Select * from SMS_Collection Where CollectionID='SMS00001'\"))\n        {\n            foreach (IResultObject collection in collections)\n            {\n                \/\/ Show collection name\n                Console.WriteLine(collection&#91;\"Name\"&#93;.StringValue);\n\n                \/\/ Get the collection object and lazy properties.  \n                collection.Get();\n\n                \/\/ Get the rules from CollectionRules which is a lazy property  \n                List&lt;IResultObject> rules = collection.GetArrayItems(\"CollectionRules\");\n                \n                if (rules.Count == 0)\n                {\n                    Console.WriteLine(\"No rules\");\n                    continue;\n                }\n\n                foreach (IResultObject rule in rules)\n                {\n                    \/\/ Display rule names.  \n                    Console.WriteLine(\"Rule name: \" + rule&#91;\"RuleName\"&#93;.StringValue);\n                }\n        \n               \/\/ Dispose the rules using our List extension method\n               rules.DisposeItems();\n            }\n        }\n    }  \n    catch (SmsQueryException ex)  \n    {  \n        Console.WriteLine(\"Failed to get collection. Error: \" + ex.Message);  \n        throw;  \n    }  \n} \n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">void<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">LazyPropertyFromQuery<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">WqlConnectionManager<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">connection<\/span><span style=\"color: #D4D4D4\">)  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">{  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">try<\/span><span style=\"color: #D4D4D4\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    {  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">        \/\/ Query the All Systems collection (this has two default rules)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">using<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #4EC9B0\">IResultObject<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">collections<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">connection<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">QueryProcessor<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">ExecuteQuery<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;Select * from SMS_Collection Where CollectionID=&#39;SMS00001&#39;&quot;<\/span><span style=\"color: #D4D4D4\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            <\/span><span style=\"color: #C586C0\">foreach<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #4EC9B0\">IResultObject<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">collection<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">collections<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">                \/\/ Show collection name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #9CDCFE\">Console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">WriteLine<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">collection<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&quot;Name&quot;<\/span><span style=\"color: #D4D4D4\">&#93;.<\/span><span style=\"color: #9CDCFE\">StringValue<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">                \/\/ Get the collection object and lazy properties.  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #9CDCFE\">collection<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">Get<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">                \/\/ Get the rules from CollectionRules which is a lazy property  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #4EC9B0\">List<\/span><span style=\"color: #D4D4D4\">&lt;<\/span><span style=\"color: #4EC9B0\">IResultObject<\/span><span style=\"color: #D4D4D4\">&gt; <\/span><span style=\"color: #9CDCFE\">rules<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">collection<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">GetArrayItems<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;CollectionRules&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #9CDCFE\">rules<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">Count<\/span><span style=\"color: #D4D4D4\"> == <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                    <\/span><span style=\"color: #9CDCFE\">Console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">WriteLine<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;No rules&quot;<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                    <\/span><span style=\"color: #C586C0\">continue<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                <\/span><span style=\"color: #C586C0\">foreach<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #4EC9B0\">IResultObject<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">rule<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">rules<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">                    \/\/ Display rule names.  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                    <\/span><span style=\"color: #9CDCFE\">Console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">WriteLine<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;Rule name: &quot;<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #9CDCFE\">rule<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #CE9178\">&quot;RuleName&quot;<\/span><span style=\"color: #D4D4D4\">&#93;.<\/span><span style=\"color: #9CDCFE\">StringValue<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">                }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">               \/\/ Dispose the rules using our List extension method<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">               <\/span><span style=\"color: #9CDCFE\">rules<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">DisposeItems<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">            }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">catch<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #4EC9B0\">SmsQueryException<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">ex<\/span><span style=\"color: #D4D4D4\">)  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    {  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #9CDCFE\">Console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">WriteLine<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;Failed to get collection. Error: &quot;<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #9CDCFE\">ex<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">Message<\/span><span style=\"color: #D4D4D4\">);  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">throw<\/span><span style=\"color: #D4D4D4\">;  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview Some Microsoft Configuration Manager (ConfigMgr) WMI classes make use of\u00a0lazy properties. These are properties that are not returned from WqlConnectionManager.ExecuteQuery() by default in order to reduce the time taken for large queries to be processed. Note When using IResultObject.Get()&nbsp;or WqlConnectionManager.GetInstance() the lazy properties&nbsp;are returned. Here is an extract of the SMS_Collection class description on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":100234,"parent":1769,"menu_order":4,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1823","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/comments?post=1823"}],"version-history":[{"count":11,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1823\/revisions"}],"predecessor-version":[{"id":100261,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1823\/revisions\/100261"}],"up":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/pages\/1769"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/media\/100234"}],"wp:attachment":[{"href":"https:\/\/www.autoitconsulting.com\/site\/wp-json\/wp\/v2\/media?parent=1823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}