Partager via


How to Create a Configuration Manager Console Search Folder

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

In Microsoft System Center Configuration Manager 2007, to create a Configuration Manager console search folder, you set the following properties of the SMS_ObjectContainerNode Server WMI Class object:

SearchFolder - Boolean value that indicates that the folder is a search folder.

SearchString - An XML data structure that defines the search. For more information, see Configuration Manager Search Folder XML.

FolderFlags - Search folder flags. In most cases this is set to 1, indicating that the search includes all folders of the same type.

To create a console search folder

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Create an SMS_ObjectContainerNode object.

  3. Set the SMS_ObjectContainerNode object SearchFolder property to true.

  4. Set the SMS_ObjectContainerNode object SearchString property to the search XML.

  5. Set the SMS_ObjectContainerNode object FolderFlags property to 1.

  6. Commit the SMS_ObjectContainerNode object.

Example

The following example creates a search folder. The parameter name is the name that the search folder is created with. The identifier for the folder that the search folder is created in, is ]parentNodeID, and searchXML is the XML search data.

The following is an example XML string for searchXML that searches for a package with the identifier JBS00004:

Note

Remove the @ character from the beginning of the string for use with VBScript.

@"<SearchFolderDescription xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" Name=""SMS_Package""><SearchFolderDescriptionItems>
    <SearchFolderDescriptionItem PropertyName=""PackageID"">
        <SearchStrings>
            <string>JBS00004</string>
        </SearchStrings>
    </SearchFolderDescriptionItem>
</SearchFolderDescriptionItems></SearchFolderDescription>"

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub  CreateSearchFolder(connection, name, objectType, parentNodeID, searchXML)

    Dim folder
          
    Set folder = connection.Get("SMS_ObjectContainerNode").SpawnInstance_()
    If Err.Number<>0 Then
        Wscript.Echo "Couldn't get container node item class"
        Exit Sub
    End If


    folder.Name = name
    folder.ObjectType = objectType
    folder.ParentContainerNodeID = parentNodeID
    folder.SearchFolder = true
    folder.SearchString = searchXML
    folder.FolderFlags = 1

    folder.Put_ 

End Sub  
public void CreateSearchFolder(WqlConnectionManager connection, string name, Int32 objectType, Int32 parentNodeID, string searchXML)
{
    try
    {

        IResultObject folder = connection.CreateInstance("SMS_ObjectContainerNode");

        folder["Name"].StringValue = name;
        folder["ObjectType"].IntegerValue = objectType;
        folder["ParentContainerNodeID"].IntegerValue = parentNodeID;
        folder["SearchFolder"].BooleanValue = true;
        folder["SearchString"].StringValue = searchXML;
        folder["FolderFlags"].IntegerValue = 1;

        folder.Put();

    }

    catch (SmsException eX)
    {
        Console.WriteLine("Failed to create search folder. Error: " + eX.Message);
        throw;
    }

}

The example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

Name

  • Managed: string

  • VBScript: string

The name of the console folder to create.

objectType

  • Managed: int32

  • VBScript: integer

The type of object the folder is being created for. For more information, see the SMS_ObjectContainerNode class ObjectType property.

parentNodeID

  • Managed:Int32

  • VBScript: Integer

The node the console folder is created in. For more information, see the SMS_ObjectContainerNode class ParentContainerNodeID property.

searchXML

  • Managed: String

  • VBScript: String

The search criteria. For more information, see Configuration Manager Search Folder XML.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also

Concepts

About Configuration Manager Console Folders
Configuration Manager Objects
Configuration Manager Search Folder XML
How to Create a Configuration Manager Console Folder
How to Create a Configuration Manager Console Folder Item
How to Delete a Configuration Manager Console Folder
How to Move a Configuration Manager Console Folder
How to Move a Configuration Manager Console Folder Item