Partager via


Guide pratique pour énumérer Mises à jour correspondant à des critères spécifiques

Cette rubrique explique comment énumérer les mises à jour logicielles qui correspondent à des critères spécifiques dans Configuration Manager en créant une requête, puis en utilisant la ExecuteQuery méthode de la QueryProcessor classe pour exécuter la requête.

Pour énumérer les mises à jour correspondant à des critères spécifiques

  1. Configurez une connexion au fournisseur SMS.

  2. Affectez une requête spécifique à une variable.

  3. Passez la variable à la ExecuteQuery méthode .

Exemple

L’exemple de méthode suivant énumère les mises à jour qui correspondent à des critères spécifiques en passant une requête à la ExecuteQuery méthode .

Quatre exemples de requêtes sont présentés ci-dessous :

  1. Requête qui affiche les mises à jour logicielles qui ont déjà été téléchargées.

  2. Requête qui affiche les mises à jour logicielles qui ont déjà été déployées.

  3. Requête qui affiche les mises à jour logicielles qui ont une valeur de gravité particulière.

  4. Requête qui affiche les CI_IDs de mise à jour logicielle associées à un article base de connaissances spécifique.

    Des informations détaillées sur les propriétés associées à une mise à jour logicielle se trouvent dans le matériel de référence de classe SMS_SoftwareUpdate .

    Pour plus d’informations sur l’appel de l’exemple de code, consultez Appel d’extraits de code Configuration Manager.


Sub EnumerateUpdatesMatchingCriteria(connection)  

    ' This query displays all updates that have already been downloaded.  
    Query1 = "Select * from SMS_SoftwareUpdate where IsContentProvisioned=1"   

    ' Run query.  
    Set ListOfResources1 = connection.ExecQuery(Query1, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)  

    ' The query returns a collection that needs to be enumerated.  
    Wscript.Echo " "  
    Wscript.Echo "Update Content Is Downloaded."  
    Wscript.Echo "Query: " & Query1  
    Wscript.Echo "--------------------------------------------------------"    

    For Each Resource1 In ListOfResources1       
        Wscript.Echo "Name:       " & Resource1.LocalizedDisplayName  
        Wscript.Echo "ArticleID:  " & Resource1.ArticleID  
        Wscript.Echo "CI_ID:      " & Resource1.CI_ID  
        Wscript.Echo "Severity:   " & Resource1.SeverityName     
    Next  

    ' This query displays the updates that have already been deployed.  
    Query2 = "Select * from SMS_SoftwareUpdate where IsDeployed=1"   

    ' Run query.  
    Set ListOfResources2 = connection.ExecQuery(Query2, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)  

    ' The query returns a collection that needs to be enumerated.  
    Wscript.Echo " "  
    Wscript.Echo "Updates Have Already Been Deployed."  
    Wscript.Echo "Query: " & Query2  
    Wscript.Echo "--------------------------------------------------------"    

    For Each Resource2 In ListOfResources2       
        Wscript.Echo "Name:       " & Resource2.LocalizedDisplayName  
        Wscript.Echo "ArticleID:  " & Resource2.ArticleID  
        Wscript.Echo "CI_ID:      " & Resource2.CI_ID  
        Wscript.Echo "Severity:   " & Resource2.SeverityName     
    Next  

    ' This query displays the updates that have a particular severity value.   
    Query3 = "Select * from SMS_SoftwareUpdate where SeverityName='Critical'"   

    ' Run query.  
    Set ListOfResources3 = connection.ExecQuery(Query3, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)  

    ' The query returns a collection that needs to be enumerated.  
    Wscript.Echo " "  
    Wscript.Echo "Updates That Have A Particular Severity Title."  
    Wscript.Echo "Query: " & Query3  
    Wscript.Echo "--------------------------------------------------------"    

    For Each Resource3 In ListOfResources3       
        Wscript.Echo "Name:       " & Resource3.LocalizedDisplayName  
        Wscript.Echo "ArticleID:  " & Resource3.ArticleID  
        Wscript.Echo "CI_ID:      " & Resource3.CI_ID  
        Wscript.Echo "Severity:   " & Resource3.SeverityName     
    Next  

       ' This query displays software updates associated with a specific knowledge base artile.  
    Query4 = "SELECT * FROM SMS_SoftwareUpdate WHERE ArticleID='832880'"   

    ' Run query.  
    Set ListOfResources4 = connection.ExecQuery(Query4, , wbemFlagForwardOnly Or wbemFlagReturnImmediately)  

    ' The query returns a collection that needs to be enumerated.  
    Wscript.Echo " "  
    Wscript.Echo "Updates For A Specific KB Article."  
    Wscript.Echo "Query: " & Query4  
    Wscript.Echo "--------------------------------------------------------"    

    For Each Resource4 In ListOfResources4       
        Wscript.Echo "Name:       " & Resource4.LocalizedDisplayName  
        Wscript.Echo "ArticleID:  " & Resource4.ArticleID  
        Wscript.Echo "CI_ID:      " & Resource4.CI_ID  
        Wscript.Echo "Severity:   " & Resource4.SeverityName     
    Next  

End Sub  


public void EnumerateUpdatesMatchingCriteria(WqlConnectionManager connection)  
{  

    //  Note:  Query strings or variables could easily be passed in to complete the strings, but the query string  
    //         must be contructed and variables resolved prior to passing the string to the ExecuteQuery method.   

    try  
    {  

        // This query displays all updates that have already been downloaded.  
        string query1 = "Select * from SMS_SoftwareUpdate where IsContentProvisioned=1";  

        // Run query.  
        IResultObject listOfResources1 = connection.QueryProcessor.ExecuteQuery(query1);  

        // The query returns a collection that needs to be enumerated.  
        Console.WriteLine(" ");  
        Console.WriteLine("Update Content Is Downloaded.");  
        Console.WriteLine("Query: " + query1);                 
        Console.WriteLine("--------------------------------------------------------");  
        foreach (IResultObject resource1 in listOfResources1)  
        {  
            Console.WriteLine();  
            Console.WriteLine("Name:       " + resource1["LocalizedDisplayName"].StringValue);  
            Console.WriteLine("Article ID: " + resource1["ArticleID"].StringValue);  
            Console.WriteLine("CI_ID:      " + resource1["CI_ID"].IntegerValue);  
            Console.WriteLine("Severity    " + resource1["SeverityName"].StringValue);  
        }  

        // This query displays the updates that have already been deployed.  
        string query2 = "Select * from SMS_SoftwareUpdate where IsDeployed=1";  

        // Run query.  
        IResultObject listOfResources2 = connection.QueryProcessor.ExecuteQuery(query2);  

        // The query returns a collection that needs to be enumerated.  
        Console.WriteLine(" ");  
        Console.WriteLine("Updates Have Already Been Deployed.");  
        Console.WriteLine("Assignments Query: " + query2);  
        Console.WriteLine("--------------------------------------------------------");  
        foreach (IResultObject resource2 in listOfResources2)  
        {  
            Console.WriteLine();  
            Console.WriteLine("Name:       " + resource2["LocalizedDisplayName"].StringValue);  
            Console.WriteLine("Article ID: " + resource2["ArticleID"].StringValue);  
            Console.WriteLine("CI_ID:      " + resource2["CI_ID"].IntegerValue);  
            Console.WriteLine("Severity:   " + resource2["SeverityName"].StringValue);  
        }  

        // This query displays the updates that have a particular severity value.  
        string query3 = "Select * from SMS_SoftwareUpdate where SeverityName='Critical'";  

        // Run query.  
        IResultObject listOfResources3 = connection.QueryProcessor.ExecuteQuery(query3);  

        // The query returns a collection that needs to be enumerated.  
        Console.WriteLine(" ");  
        Console.WriteLine("Updates That Have A Particular Severity Title.");  
        Console.WriteLine("Query: " + query3);  
        Console.WriteLine("--------------------------------------------------------");  
        foreach (IResultObject resource3 in listOfResources3)  
        {  
            Console.WriteLine();  
            Console.WriteLine("Name:       " + resource3["LocalizedDisplayName"].StringValue);  
            Console.WriteLine("Article ID: " + resource3["ArticleID"].StringValue);  
            Console.WriteLine("CI_ID:      " + resource3["CI_ID"].IntegerValue);  
            Console.WriteLine("Severity:   " + resource3["SeverityName"].StringValue);  
        }  

        // This query displays software updates associated with a specific KB.  
        string query4 = "SELECT * FROM SMS_SoftwareUpdate WHERE ArticleID='832880'";  

        // Run query.  
        IResultObject listOfResources4 = connection.QueryProcessor.ExecuteQuery(query4);  

        // The query returns a collection that needs to be enumerated.  
        Console.WriteLine(" ");  
        Console.WriteLine("Updates For A Specific KB Article.");  
        Console.WriteLine("Query: " + query4);  
        Console.WriteLine("--------------------------------------------------------");  
        foreach (IResultObject resource4 in listOfResources4)  
        {  
            Console.WriteLine();  
            Console.WriteLine("Name:       " + resource4["LocalizedDisplayName"].StringValue);  
            Console.WriteLine("Article ID: " + resource4["ArticleID"].StringValue);  
            Console.WriteLine("CI_ID:      " + resource4["CI_ID"].IntegerValue);  
            Console.WriteLine("Severity:   " + resource4["SeverityName"].StringValue);  
        }  
    }  

    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed to run queries. Error: " + ex.Message);  
        throw;  
    }  
}  

L’exemple de méthode a les paramètres suivants :

Paramètre Type Description
connection -Géré: WqlConnectionManager
- VBScript : SWbemServices
Connexion valide au fournisseur SMS.

Compilation du code

Cet exemple C# nécessite :

Espaces de noms

Système

System.Collections.Generic

System.Text

Microsoft. ConfigurationManagement.ManagementProvider

Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Programmation robuste

Pour plus d’informations sur la gestion des erreurs, consultez À propos des erreurs Configuration Manager.

Sécurité de .NET Framework

Pour plus d’informations sur la sécurisation des applications Configuration Manager, consultez Configuration Manager’administration basée sur les rôles.

Voir aussi

A propos des déploiements de mise à jour logicielles

SMS_SoftwareUpdate