Find text in an XML string or document using an XPath query.

      Select-XML -Content string[] [-Xpath] string
         [-Namespace hashtable] [CommonParameters]

      Select-XML [-Path] string[] [-Xpath] string
         [-Namespace hashtable] [CommonParameters]

      Select-XML [-Xml] XmlNode[] [-Xpath] string
         [-Namespace hashtable] [CommonParameters]

   -Content string[]
       A string that contains the XML to search.
       You can also pipe strings to Select-XML.

    -Namespace hashtable
       A hash table of the namespaces used in the XML.
       Use the format @{namespaceName = namespaceValue}.

   -Path path
       The path and file names of the XML files to search.
       Wildcards are permitted.

   -Xml XmlNode[]
       One or more XML nodes.
       A Path or XML parameter is required in every command.
       An XML document will be processed as a collection of XML nodes.
       If an XML document is passed to Select-XML, each
       document node will be searched separately as it comes through the pipeline.
   -Xpath string
       An XPath search query.
       The query language is case-sensitive. This parameter is required.


Search the Types.ps1xml file for child items of the AliasProperty node:

PS C:\> $path = "$env:windir\System32\WindowsPowerShell\v1.0\Types.ps1xml"
PS C:\> select-xml -path $path -xpath "/Types/Type/Members/AliasProperty"

Search in several XML files:

PS C:\> select-xml -path test*.xml, help.xml -xpath "/Tests/Test[1]/Name"

Pipe an XML document to Select-XML:

PS C:\> [xml]$Types = get-content "$env:windir\System32\WindowsPowerShell\v1.0\Types.ps1xml"
PS C:\> select-xml -xml $Types -xpath "//MethodName"

"Content is king" - Webmonkey circa 1996

Related PowerShell Cmdlets

ConvertTo-Xml - Convert the input into XML

Copyright © 1999-2023
Some rights reserved