> For the complete documentation index, see [llms.txt](https://docs.lithnet.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lithnet.io/resource-management-powershell/usage/cmdlet-reference/new-xpathquerygroup.md).

# New-XPathQueryGroup

### Description

The `New-XPathQueryGroup` cmdlet create a new group of query objects that can be used to create an XPath expression using [New-XPathExpression](/resource-management-powershell/usage/cmdlet-reference/new-xpathexpression.md), or an element in an XPath query group using [New-XPathQueryGroup](/resource-management-powershell/usage/cmdlet-reference/new-xpathquerygroup.md). The resulting [XPathExpression](/resource-management-powershell/usage/cmdlet-reference/new-xpathexpression.md) can be passed as a parameter to [Search-Resources](/resource-management-powershell/usage/cmdlet-reference/search-resources.md). An XPath query group contains one or more [Xpath query](/resource-management-powershell/usage/cmdlet-reference/new-xpathquery.md) objects or other XPathQueryGroup objects.

### Syntax

```
New-XpathQueryGroup [-Operator] <GroupOperator> {And | Or} [[-Queries] <IXPathQueryObject[]>]  
```

### Parameters

#### Operator

Required. Specifies the logical operator to use when comparing queries within the group. The support values are `And` and `Or`

#### Queries

Required. One or more query objects generated with the [New-XPathQuery](/resource-management-powershell/usage/cmdlet-reference/new-xpathquery.md) or [New-XPathQueryGroup](/resource-management-powershell/usage/cmdlet-reference/new-xpathquerygroup.md) cmdlets

### Examples

#### Viewing the query group string

The `New-XPathQueryGroup` does not return a usable query itself. It returns only a part of the query that is used in an XPath expression. You can view the query component itself as shown in the following example.

```powershell
$query1 = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$query2 = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "bob"
$queryGroup = New-XPathQueryGroup -Operator Or -Queries @($query1, $query2)
$queryGroup .ToString()
```

This returns an string representing the query component

```
((AccountName = 'ryan') or (AccountName = 'bob'))
```

#### Building a simple query

In order to use the query, it must be rendered by an XPath expression created with the \[\[New-XPathExpression]] cmdlet

```powershell
$query1 = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$query2 = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "bob"
$queryGroup = New-XPathQueryGroup -Operator Or -Queries ($query1, $query2)
$expression = New-XPathExpression -ObjectType "Person" -QueryObject $queryGroup 
$expression.ToString()
```

This returns an expression containing the query

```
/Person[((AccountName = 'ryan') or (AccountName = 'bob'))]
```

#### Building a nested query

A query group can contain other groups as well as standard queries.

```powershell
$query1 = New-XPathQuery -AttributeName "DisplayName" -Operator StartsWith -Value "ryan"
$query2 = New-XPathQuery -AttributeName "DisplayName" -Operator Equals -Value "bob"
# Create the child group
$queryGroup1 = New-XPathQueryGroup -Operator Or -Queries @($query1, $query2)
$query3 = New-XPathQuery -AttributeName "Email" -Operator IsPresent
# Create the parent group using the child group and another query
$queryGroup2 = New-XPathQueryGroup -Operator And -Queries @($query3, $queryGroup1)
$expression = New-XPathExpression -ObjectType "Person" -QueryObject $queryGroup2
$expression.ToString()
```

The expression generated is as follows

```
/Person[((starts-with(Email, '%')) and ((starts-with(DisplayName, 'ryan')) or (DisplayName = 'bob')))]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lithnet.io/resource-management-powershell/usage/cmdlet-reference/new-xpathquerygroup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
