Select-XML

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

Syntax
      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]

Key
   -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.

Examples

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

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

Search in several XML files:

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

Pipe an XML document to Select-XML:

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

"Content is king" - Webmonkey @Wired.com circa 1996

Related PowerShell Cmdlets:

ConvertTo-Xml - Convert the input into XML


 
Copyright © 1999-2020 SS64.com
Some rights reserved