A.11 Search Operations

You can create .NET applications to perform searches using GPA. If you are running GPA on a 64‑bit platform, run these applications using a 32‑bit command prompt window. On a 64‑bit computer, you can access the 32‑bit command prompt window from the %WINDIR%\SysWOW64 folder.

To create a .NET application:

  1. Create a console application in Microsoft Visual Studio.

    NOTE:Ensure the logged on user account has Write permission on the GPA install location/Bin folder.

  2. In Solution Explorer, right-click on your project name and select Properties.

  3. Select the Build tab and change the output path to GPA install location/Bin.

  4. In Solution Explorer select References, then right-click on Reference and select Add Reference.

  5. Select the Browse tab, navigate to your GPA install location, and add the following assemblies:

    • NetiQ.GPA.SearchAPI.dll
    • NetiQ.GPA.SearchHelpers.dll
  6. Add the following libraries at the beginning of each application:

    • using NetIQ.GPA.SearchComponentHelper;
    • using NetiQ.GPA.SearchAPI;
  7. If you are using multiple search criteria, include the following library at the beginning of the application:

    • using System.Collections;

The following sections contain samples of searching using a single criterion and searching using multiple criteria.

NOTE:GPA returns these search results in XML format.

A.11.1 GPO Name

The following sample allows you to search for GPOs by name using the contains/does not contain/is exactly condition.

  • Note that Is Exactly = opEquals
public void SearchForGPONAME()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like GPO Name.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gpoDisplayName;
                    //Search Conditions like contains, Does not contains, Is exactly.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opContains;
                    //Create Search query for example (GPO Name Contains 'gpo') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "gpo");
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid AD domain, where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
 //Create scope for repository domain search .
                    GPASearchScope.AddRepositoryDomain();                    
 //Search for AD GPOs, REP GPOs or both.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.2 GPO Links

The following sample allows you to search for GPOs by links using the Exist in/Does not exist in condition

public void SearchForGPOLinks()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like GPO Links.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gposomLinks;
                    //Search Conditions like Exist in, Does not exist in.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opExistIn;
                    //Create Search query for example (GPO Links Exist in '[All Sites]') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "[All Sites]");
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();                    
                    //Assign valid AD domain, where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
 //Create scope for repository domain search .
                    GPASearchScope.AddRepositoryDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs, REP GPOs or both.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.3 Security Group

The following sample allows you to search for GPOs by security group using the Has this explicit permission/Does not have this explicit permission/Has this effective permission/Does not have this effective permission condition.

public void SearchForSecurityGroup()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like Security Group.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gpoSecurityGroup;
                    //Search Conditions like Has this explicit permission, Does not have this explicit permission,
                    //Has this effective permission, Does not have this effective permission.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opHasExplicitPermission;
                    //Create Search query for example (NetIQLabs.com\JSmith Has this explicit permission 'Apply settings') 
                    //'Apply settings' = 1
                    //'Edit settings' = 2
                    //'Edit settings, delete, modify security' = 3
                    //'Read settings' = 4
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "1","MYDOMAIN.LAB/user|group");  
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid domain, where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.4 Linked WMI Filter

The following sample allows you to search for GPOs by linked WMI filter using the Is/Is not condition.

  • Note that Is = opEquals
  • Is Not = opNotEquals
public void SearchForWMIFilter()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like WMI Filter.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gpoWMIFilter;
                    //Search Conditions like Is, Is Not.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opEquals;
                    //Create Search query for example (WMI Filter is 'operating system') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "operating system");                 
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid AD domain, where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
                    //Create scope for repository domain search .
                    GPASearchScope.AddRepositoryDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs and REP GPOs.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInADAndREP);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.5 User Configuration

The following sample allows you to search for GPOs by user configuration using the contains/does not contain condition.

public void SearchUserConfigurationSetting()
        {
            try
            {
                //Instantiate the Search Criteria Builder.
                IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                if (null == gpaSearchCriteriaBuilder)
                {
                    Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                    return;
                }

    //For User Configuration.
                //Search query : (User Configuration Contains 'Deployed Printer Connections')
                IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(GPASearchCriterionTypes.gpoUserExtensions,
                                                                                  GPASearchOperatorTypes.opContains,
                                                                                  "Deployed Printer Connections");
                //Create the search scope
                IGPASearchScope GPASearchScope = new GpaSearchScope();

                //Assign valid domain, where intended to do search.
                GPASearchScope.AddRepositoryDomain("MYDOMAIN.LAB", "");

                //Search for AD GPOs.
                GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInREP);

    //Instantiate the GPAsearchAPI
     IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                if (null == oGPASearchAPI)
                {
                    Console.WriteLine("Failed to instance of GpaSearchAPI");
                    return;
                }

                //Initialize the Search API.
                bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                if (bstatus)
                {
                    // Get the Search Request ID.
                    string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                    if (strSearchRequestID.Length > 0)
                    {
                        oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                    }

                }
            }
            catch (Exception genExp)
            {
                Console.WriteLine("Failed to Search." + genExp.Message);
            }
        }

A.11.6 Computer Configuration

The following sample allows you to search for GPOs by computer configuration using the contains/does not contain condition.

public void SearchComputerConfigurationSetting()
        {
            try
            {
                //Instantiate the Search Criteria Builder.
                IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                if (null == gpaSearchCriteriaBuilder)
                {
                    Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                    return;
                }

                //Computer Configuration
                //Sample Search query : (User Configuration Contains '802.3 Group Policy')
                IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(GPASearchCriterionTypes.gpoComputerExtensions,
                                                                                  GPASearchOperatorTypes.opContains, 
                                                                                  "802.3 Group Policy");
                //Create the search scope
                IGPASearchScope GPASearchScope = new GpaSearchScope();

                //Assign valid domain, where intended to do search.
                GPASearchScope.AddRepositoryDomain("MYDOMAIN.LAB", "");

                //Search for AD GPOs.
                GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInREP);

    //Instantiate the GPAsearchAPI
                IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                if (null == oGPASearchAPI)
                {
                    Console.WriteLine("Failed to instance of GpaSearchAPI");
                    return;
                }

                //Initialize the Search API.
                bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                if (bstatus)
                {
                    // Get the Search Request ID.
                    string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                    if (strSearchRequestID.Length > 0)
                    {
                        oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                    }

                }
            }
            catch (Exception genExp)
            {
                Console.WriteLine("Failed to Search." + genExp.Message);
            }
        }

A.11.7 GUID Configuration

The following sample allows you to search for GPOs by GUID configuration using the equals condition.

public void SearchForGUID()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like GUID.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gpoGUID;
                    //Search Conditions like Equals.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opEquals;
                    //Create Search query for example (GUID Equals '{DC047537-A1C0-4212-81D7-D2674D98AA89}') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "{DC047537-A1C0-4212-81D7-D2674D98AA89}");  
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid domain, where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.8 Keyword

The following sample allows you to search for GPOs by keyword using the Contains condition.

public void SearchForKeywordSearch()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like Keyword.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gpoKeyword;
                    //Search Conditions like Contains.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opContains;
                    //Create Search query for example (Keyword Contains 'Certificate Services Client - Auto-Enrollment') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "Certificate Services Client - Auto-Enrollment");  
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid domain, where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.9 Advanced Keyword

The following sample allows you to search for GPOs by advanced keyword using the Contains/Begins with/Ends with/Equals condition.

public void SearchForAdvanceKeywordSearch()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Advance Keyword search Item.
                    GPASearchCriterionTypes eSearchCriteriaType = GPASearchCriterionTypes.gpoAdvancedKeyword;
                    //Setting Name Operator like Contains, Begins with, Ends with, Equals.
                    GPASearchOperatorTypes eSettingNameOperator = GPASearchOperatorTypes.opContains;
                    //Setting Name Operand.
                    string strSettingNameOperand = "Configure Automatic Updates";
                    //Setting Value Operator like Contains, Begins with, Ends with, Equals.
                    GPASearchOperatorTypes eSettingValueOperator = GPASearchOperatorTypes.opBeginsWith;
                    //Setting Value Oprand.
                    string strSettingValueOprand = "Enabled";
                    //Create Search query for example (Advanced Keyword Search Setting Name Contains 'Configure Automatic Updates' And Setting Value Begins with 'Enabled') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(eSearchCriteriaType,
                                                                                                             eSettingNameOperator,
                                                                                                             strSettingNameOperand,
                                                                                                             eSettingValueOperator,
                                                                                                             strSettingValueOprand);
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid domain where intended to do search.
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.10 GPO Search Using Multiple Criteria

The following sample allows you to search for GPOs using multiple criteria.

public void SearchForMultipleSearchCriteria()
            {
                try
                {
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    IList participantArrayList = new ArrayList();
                    IGPASearchParticipant Participant;
                    //First Search Item: GPO Name
                    //Search query : (GPO Name Contains 'rc') 
                    Participant = gpaSearchCriteriaBuilder.CreateSearchFilter(GPASearchCriterionTypes.gpoDisplayName,
                                                                              GPASearchOperatorTypes.opContains,
                                                                              "rc");
                    //Add the Search query to the array list.
                    participantArrayList.Add(Participant);
                   
                    //Second Search Item: GPO Links
                    //Search query : (GPO Links Exist In 'MYDOMAIN.LAB')
                    Participant = gpaSearchCriteriaBuilder.CreateSearchFilter(GPASearchCriterionTypes.gposomLinks,
                                                                              GPASearchOperatorTypes.opExistIn,
                                                                              "MYDOMAIN.LAB");
                    //Add the Search query to the array list.
                    participantArrayList.Add(Participant);

                    //Third Search Item: Keyword search
                    //Search query : (Keyword Contains 'Enabled')
                    Participant = gpaSearchCriteriaBuilder.CreateSearchFilter(GPASearchCriterionTypes.gpoKeyword,
                                                                              GPASearchOperatorTypes.opContains,
                                                                              "Enabled");
                    //Add the Search query to the array list.
                    participantArrayList.Add(Participant);                    
                    //List of search queries.
                    IGPASearchParticipant gpaSearchParticipantList;
                    //Final Search queries : (GPO Name Contains 'rc')AND(GPO Links Exist In 'MYDOMAIN.LAB')AND(Keyword Contains 'Enabled')
                    //Relation Type of search: Match All Criteria = AND, Match Any Criteria = OR
                    gpaSearchParticipantList = gpaSearchCriteriaBuilder.LinkSearchCriteriaEx(participantArrayList, GPASearchRelationshipType.AND/*Relation Type*/);
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    GPASearchScope.AddDomain("MYDOMAIN.LAB", "");
                    //Create scope for repository domain search .
                    GPASearchScope.AddRepositoryDomain("MYDOMAIN.LAB", "");
                    //Search for AD GPOs.
                    //GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Search for REP GPOs.
                    //GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInREP);
                    //Search for AD GPOs and REP GPOs.
                    GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInADAndREP);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bresult = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bresult)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipantList, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }

A.11.11 GPO Search Using Multiple Domains

The following sample allows you to search for GPOs in multiple domains.

public void SearchForMultipleDomain()
            {
                try
                {
                    //Instantiate the Search Criteria Builder.
                    IGPASearchCriteriaBuilder gpaSearchCriteriaBuilder = new CGPASearchCriteriaBuilder();
                    if (null == gpaSearchCriteriaBuilder)
                    {
                        Console.WriteLine("Failed to create NetIQGPASearchHelpers.CGPASearchCriteriaBuilder");
                        return;
                    }
                    //Search Item like GPO Name.
                    GPASearchCriterionTypes cTypes = GPASearchCriterionTypes.gpoDisplayName;
                    //Search Conditions like Contains.
                    GPASearchOperatorTypes oTypes = GPASearchOperatorTypes.opContains;
                    //Create Search query for example (GPO Name Contains 'rc_') 
                    IGPASearchParticipant gpaSearchParticipant = gpaSearchCriteriaBuilder.CreateSearchFilter(cTypes, oTypes, "rc_");                 
                    //Create the search scope
                    IGPASearchScope GPASearchScope = new GpaSearchScope();
                    //Assign valid AD domains, where intended to do search.
                    GPASearchScope.AddDomain("AD_Domain A", "");
                    GPASearchScope.AddDomain("AD_Domain B", "");
                    // Assign valid Repository domains, where intended to do search.
                    GPASearchScope.AddRepositoryDomain("REP_Domain A", "");
                    GPASearchScope.AddRepositoryDomain("REP_Domain B", "");
                    //Search for AD GPOs.
                        //GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInAD);
                    //Search for REP GPOs.
                        //GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInREP);
                    //Search for AD GPOs and REP GPOs.
                        GPASearchScope.AddOptions(SearchOptions.SearchType, SearchType.SearchInADAndREP);
                    //Instantiate the GPAsearchAPI
                    IGPASearchAPIs oGPASearchAPI = new GpaSearchAPI();
                    //Initialize the Search API.
                    bool bstatus = oGPASearchAPI.Initialize("Server_host_name", "http", 63847);
                    if (bstatus)
                    {
                        // Get the Search Request ID.
                        string strSearchRequestID = oGPASearchAPI.SearchGPOs(gpaSearchParticipant, GPASearchScope);
                        if (strSearchRequestID.Length > 0)
                        {
                            // Save the search xml.
                            oGPASearchAPI.GetSearchResult(strSearchRequestID, "File_Location\\Filename.xml");
                        }
                    }
                }
                catch (Exception genExp)
                {
                    Console.WriteLine("Failed to Search." + genExp.Message);
                }
            }