none
c# query sccm for mac address

    Question

  • Can someone please help me. I am trying to query sccm for a mac address. I was able to complete the task using powershell. Here is whet I have

    SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();

                sccmConnect.Connect("Servername");

                string query1 = string.Format("select SMS_R_System.MACAddresses, SMS_R_System.IPAddresses,SMS_R_System.IPSubnets, SMS_R_System.LastLogonUserName from  SMS_R_System where SMS_R_System.Name = 'CN'");

                IResultObject queryResults = sccmConnect.QueryProcessor.ExecuteQuery(query1);

                bool resultsFound = false;

                foreach (IResultObject queryResult in queryResults)

                {

                    resultsFound = true;

                    Console.WriteLine(queryResult);


    Freddy91761_1


    • Edited by Freddy91761_1 Wednesday, January 17, 2018 7:44 PM update
    Wednesday, January 17, 2018 7:43 PM

All replies

  • Can someone please help me. I am trying to query sccm for a mac address. I was able to complete the task using powershell. Here is whet I have

    SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();

                sccmConnect.Connect("Servername");

                string query1 = string.Format("select SMS_R_System.MACAddresses, SMS_R_System.IPAddresses,SMS_R_System.IPSubnets, SMS_R_System.LastLogonUserName from  SMS_R_System where SMS_R_System.Name = 'CN'");

                IResultObject queryResults = sccmConnect.QueryProcessor.ExecuteQuery(query1);

                bool resultsFound = false;

                foreach (IResultObject queryResult in queryResults)

                {

                    resultsFound = true;

                    Console.WriteLine(queryResult);


    Freddy91761_1


    You should ask this question within a C# forum. 

    Garth Jones

    Blog: http://www.enhansoft.com/blog Old Blog: http://smsug.ca/blogs/garth_jones/default.aspx

    Twitter: @GarthMJ Book: System Center Configuration Manager Reporting Unleased

    Wednesday, January 17, 2018 10:22 PM
  • You queryResult is of the type IResultObject, so you will have to look a how to extract property values from that.

    For MACAddresses it is a string array, why you would want to use the StringArrayValue like this

    var macAddresses;
    foreach (IResultObject queryResult in queryResults)
    {
        resultsFound = true;
        macAddresses= queryResult["MACAddresses"].StringArrayValue;
    }

    Best regards

    Flemming Appelon Christiansen

    Thursday, January 18, 2018 8:33 AM