none
C# with SCCM connecting and Query and show results on the textbox RRS feed

  • Question

  • I would like to connect to sccm and query sccm from a computer. Here is my code

    SmsNamedValuesDictionary namedValues =

    new SmsNamedValuesDictionary();

                WqlConnectionManager connection =

    new WqlConnectionManager(namedValues);

                connection.Connect("ServerName");       

    string query = "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 =" + txtName.Text + "'";

    try

                {

                    IResultObject queryResults = connection.QueryProcessor.ExecuteQuery(query);  

    foreach (WqlResultObject obj in queryResults)

                    {          

    var macaddress = obj.GetSingleItem("SMS_R_System.MACAddresses").PropertyList["MACAddress"];

    if (macaddress != null)

                        {

                            Console.WriteLine(macaddress);

                        }

                    }

                } 

    catch(SmsException ex)

                {

                    Console.WriteLine(

    "Failed to execute query: '" + query + "': " + ex.Message + "\nInner Exception:" + ex.InnerException.Message);

             

    throw ex

                }

            }

    Here is the error I get:

    Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlQueryException: 'The SMS Provider reported an error.'


    Freddy91761_1


    I am not doing an inner join
    • Edited by Freddy91761_1 Tuesday, January 23, 2018 4:02 PM update
    Tuesday, January 23, 2018 4:00 PM

All replies

  • If this is literally your code:

    string query = "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 =" + txtName.Text + "'";

    Then the problem is that you are missing a single quote mark just after the equal sign.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Tuesday, January 23, 2018 8:43 PM