> 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/v1.0/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/v1.0/usage/cmdlet-reference/new-xpathexpression.md), or an element in an XPath query group using [New-XPathQueryGroup](/resource-management-powershell/v1.0/usage/cmdlet-reference/new-xpathquerygroup.md). The resulting [XPathExpression](/resource-management-powershell/v1.0/usage/cmdlet-reference/new-xpathexpression.md) can be passed as a parameter to [Search-Resources](/resource-management-powershell/v1.0/usage/cmdlet-reference/search-resources.md). An XPath query group contains one or more [Xpath query](/resource-management-powershell/v1.0/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/v1.0/usage/cmdlet-reference/new-xpathquery.md) or [New-XPathQueryGroup](/resource-management-powershell/v1.0/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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
