CmdID

CmdID / PowerShell / Cmdlets / Select

Select-Xml

Finds text in an XML string or document. PowerShell reference

From the PowerShell reference 6 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Finds text in an XML string or document. The Select-Xml cmdlet lets you use XPath queries to search for text in XML strings and documents. Enter an XPath query, and use the Content, Path, or Xml parameter to specify the XML to be searched.

Select-Xml [-XPath] <string> [-Xml] <XmlNode[]> [-Namespace <hashtable>] [<CommonParameters>]
Select-Xml [-XPath] <string> [-Path] <string[]> [-Namespace <hashtable>] [<CommonParameters>]
Select-Xml [-XPath] <string> -LiteralPath <string[]> [-Namespace <hashtable>] [<CommonParameters>]
Select-Xml [-XPath] <string> -Content <string[]> [-Namespace <hashtable>] [<CommonParameters>]

Select AliasProperty nodes

$Path = "$PSHOME\Types.ps1xml" $XPath = "/Types/Type/Members/AliasProperty" Select-Xml -Path $Path -XPath $Xpath | Select-Object -ExpandProperty NodeIdentify

Input an XML document

[xml]$Types = Get-Content $PSHOME\Types.ps1xml Select-Xml -Xml $Types -XPath "//MethodName"Identify

Search PowerShell Help files

$Namespace = @{ command = "http://schemas.microsoft.com/maml/dev/command/2004/10" maml = "http://schemas.microsoft.com/maml/2004/10" dev = "http://schemas.microsoft.com/maml/dev/2004/10" } $Path = "$PSHOME\en-US\*dll-Help.xml" $Xml = Select-Xml -Path $Path -Namespace $Namespace -XPath "//command:name" $Xml | Format-Table @{Label="Name"; Expression= {($_.Node.InnerXml).Trim()}}, Path -AutoSizeIdentify

Different ways to input XML

$Xml = @" <?xml version="1.0" encoding="utf-8"?> <Book> <projects> <project name="Book1" date="2009-01-20"> <editions> <edition language="English">En.Book1.com</edition> <edition language="German">Ge.Book1.Com</edition> <edition language="French">Fr.Book1.com</edition> <edition language="Polish">Pl.Book1.com</edition> </editions> </project> </projects> </Book> "@ Select-Xml -Content $Xml -XPath "//edition" | foreach {$_.Node.InnerXml} En.Book1.com Ge.Book1.Com Fr.Book1.com Pl.Book1.com $Xml | Select-Xml -XPath "//edition" | foreach {$_.Node.InnerXml} En.Book1.com Ge.Book1.Com Fr.Book1.com Pl.Book1.comIdentify

Use the default xmlns namespace

$SnippetNamespace = @{snip = "http://schemas.microsoft.com/PowerShell/Snippets"} Select-Xml -Path $HOME\Documents\WindowsPowerShell\Snippets -Namespace $SnippetNamespace -XPath "//snip:Title" | ForEach-Object {$_.Node.InnerXml}Identify

Its page in the reference: Select-Xml.

Parameters

6 in the PowerShell reference
-ContentSpecifies a string that contains the XML to search. You can also pipe strings to Select-Xml.
-LiteralPathSpecifies the paths and file names of the XML files to search. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
-NamespaceSpecifies a hash table of the namespaces used in the XML. Use the format@{<namespaceName> = <namespaceValue>}. When the XML uses the default namespace, which begins with xmlns, use an arbitrary key for the namespace name. You cannot use xmlns. In the XPath statement, prefix each node name with the namespace name and a colon, such as //namespaceName:Node.
-PathSpecifies the path and file names of the XML files to search. Wildcard characters are permitted.
-XmlSpecifies one or more XML nodes. An XML document will be processed as a collection of XML nodes. If you pipe an XML document to Select-Xml, each document node will be searched separately as it comes through the pipeline.
-XPathSpecifies an XPath search query. The query language is case-sensitive. This parameter is required.