Resource Management Powershell
Documentation Home
  • Home
  • Installation
    • Installing the PowerShell module
  • Configuration
    • Configuration management
    • ConfigSync File
    • Variables File
      • <Variables> element
        • <Variable> element
    • <Operations> element
      • <ResourceOperation> element
      • <AnchorAttributes> element
      • <AnchorAttribute> element
      • <AttributeOperations> element
        • <AttributeOperation> element
    • Building references
  • Usage
    • Cmdlet reference
      • Set-ResourceManagementClient
      • Get-Resource
      • Save-Resource
      • Search-Resources
      • Search-ResourcesPaged
      • Remove-Resource
      • New-Resource
      • Update-ResourceManagementClientSchema
      • Import-RMConfig
      • New-XPathQuery
      • New-XPathQueryGroup
      • New-XPathExpression
      • Get-ApprovalRequest
      • Set-PendingApprovalRequest
  • help and support
    • Quick reference guide
    • Working with different data and attribute types
    • XPath expression examples
Powered by GitBook
On this page
  • Description
  • Syntax
  • Parameters
  • Examples
  1. Usage
  2. Cmdlet reference

New-XPathExpression

PreviousNew-XPathQueryGroupNextGet-ApprovalRequest

Last updated 2 years ago

Description

The New-XPathExpression cmdlet create an XPath expression that can be used in the following manners

  • As an input to the cmdlet

  • As an input to the cmdlet

  • By using the ToString() method, you can generate an expression to use elsewhere in your script

  • When setting a resource attribute that expects a Filter type

The cmdlet takes a query or group generated with the or cmdlets and produces an XPath expression that can be used in the manners described above.

For a full list of examples filters generated by the XPath cmdlets, see the page.

Syntax

New-XpathExpression [-ObjectType] <string> [-QueryObject] <IXPathQueryObject> [[-DereferenceAttribute] <string>] [[-WrapFilterXml]]

Parameters

ObjectType

Required. The type of object to query. To search on all object types, use the value *

QueryObject

Required. The query or group generated using the or cmdlet

DereferenceAttribute

Optional. Specifies a reference-type attribute to query. See the example section for more information.

WrapFilterXml

Optional. Specifies that the resulting XPath expression should be wrapped in the filter XML element used when setting the Filter attribute on sets and groups.

Examples

Creating a basic expression

# Creates an expression that searches for users with the account name 'ryan'
$query = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$expression = New-XPathExpression -ObjectType "Person" -QueryObject $query
$expression.ToString()

This returns an expression containing the query

/Person[(AccountName = 'ryan')]

Passing the expression to the Search-Resources cmdlet

# Creates an expression that searches for users with the account name 'ryan'
$query = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$expression = New-XPathExpression -ObjectType "Person" -QueryObject $query
Search-Resources $expression

Building an expression to dereference an object

# Creates an expression that returns the manager of a user who has the account name 'ryan'
$query = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$expression = New-XPathExpression -ObjectType "Person" -QueryObject $query -DereferenceAttribute "Manager"
$expression.ToString()

This returns the following expression

/Person[(AccountName = 'ryan')]/Manager

You can also use a nested expression to find all users who have the person with the account name of 'ryan' as their manager

# Build an expression to find a user by its account name
$query = New-XpathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$expression = New-XpathExpression -ObjectType "Person" -Query $query

# Build a query to find all users with a manager who has the account name 'ryan'
$derefQuery = New-XpathQuery -AttributEName "Manager" -Operator Equals -Value $expression
$derefExpression = New-XpathExpression Person $derefQuery
$derefExpression.ToString()

This returns an expression containing the query

/Person[(Manager = /Person[(AccountName = 'ryan')])]

Building a filter expression

When using the expression builder to create an value to use in a Filter attribute in a set or group, you can specify that the resulting expression should be wrapped in the XML filter element.

$query = New-XPathQuery -AttributeName "AccountName" -Operator Equals -Value "ryan"
$expression = New-XPathExpression -ObjectType "Person" -QueryObject $query -WrapFilterXml
$expression.ToString()

The resulting string is as follows

<Filter xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Dialect="http://schemas.microsoft.com/2006/11/XPathFilterDialect" xmlns="http://schemas.xmlsoap.org/ws/2004/09/enumeration">/Person[(AccountName = 'ryan')]</Filter>

The expression can be passed directly to the cmdlet to search for objects

The expression builder supports dereferencing expressions, as supported by the . The following example finds the manager of a user with the account name 'ryan'

Search-Resources
Resource Management Service
New-XPathQuery
New-XPathQuery
New-XPathQueryGroup
XPath expression examples
New-XPathQuery
New-XPathQueryGroup
Search-Resources