powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Select-Xml



NAME
Select-XML

SYNOPSIS
Finds text in an XML string or document.

SYNTAX
Select-XML -Content [-Xpath] [-Namespace ] []

Select-XML [-Path] [-Xpath] [-Namespace ] []

Select-XML [-Xml] [-Xpath] [-Namespace ] []


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


PARAMETERS
-Content
Specifies a string that contains the XML to search. You can also pipe strings to Select-XML.

Required? true
Position? named
Default value None
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

-Namespace
Specifies a hash table of the namespaces used in the XML. Use the format @{ = }.

Required? false
Position? named
Default value None
Accept pipeline input? false
Accept wildcard characters? false

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

Required? true
Position? 2
Default value None
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? true

-Xml
Specifies 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 you pipe an XML document to Select-XML, each
document node will be searched separately as it comes through the pipeline.

Required? true
Position? 2
Default value None
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-Xpath
Specifies an XPath search query. The query language is case-sensitive. This parameter is required.

Required? true
Position? 1
Default value None
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.String or System.Xml.XmlNode
You can pipe a path or XML node to Select-XML.


OUTPUTS
System.Xml.XmlElement or System.Xml.XmlText



NOTES


XPath is a standard language that is designed to identify parts of an XML document. For more information about
the XPath language, see the "Selection Filters" section of the "Event Selection" topic in the MSDN (Microsoft D
eveloper Network) library at http://go.microsoft.com/fwlink/?LinkId=143608. And, see "XPath Reference" in the M
SDN library at http://go.microsoft.com/fwlink/?LinkId=143609.


-------------------------- EXAMPLE 1 --------------------------

C:\PS>$path = "$env:windir\System32\WindowsPowerShell\v1.0\Types.ps1xml"

C:\PS> select-xml -path $path -xpath "/Types/Type/Members/AliasProperty"


Description
-----------
This example searches the Types.ps1xml file for child items of the AliasProperty node.





-------------------------- EXAMPLE 2 --------------------------

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


Description
-----------
This command uses Select-XML to search in several XML files.





-------------------------- EXAMPLE 3 --------------------------

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

C:\PS> select-xml -xml $Types -xpath "//MethodName"


Description
-----------
This example shows how to pipe an XML document to Search-Path.





-------------------------- EXAMPLE 4 --------------------------

C:\PS>$namespace = @{command="http://schemas.microsoft.com/maml/dev/command/2004/10"; maml="http://schemas.microsof
t.com/maml/2004/10"; dev="http://schemas.microsoft.com/maml/dev/2004/10"}

C:\PS> $path = "$env:windir\System32\WindowsPowerShell\V1.0\en-us\*dll-Help.xml"

C:\PS> select-xml -path $path -namespace $namespace -xpath "//command:name"

Text Node Path
---- ---- ----
Add-Computer name C:\Windows\System32\WindowsPowerShell\V...
Add-Content name C:\Windows\System32\WindowsPowerShell\V...
Checkpoint-Computer name C:\Windows\System32\WindowsPowerShell\V...
Clear-Content name C:\Windows\System32\WindowsPowerShell\V...
Clear-EventLog name C:\Windows\System32\WindowsPowerShell\V...
...


Description
-----------
This example shows how to use the Select-XML cmdlet to search the Windows PowerShell XML-based cmdlet help files.

The first command creates a hash table that represents the XML namespace and saves it in the $namespace variable.

The second command saves the path to the help files in the $path variable.

The third command uses Select-Xml to search the XML for cmdlet names by finding Command:Name tags anywhere in the f
iles.





-------------------------- EXAMPLE 5 --------------------------

C:\PS>select-xml -content $xml -xpath "//edition"

C:\PS> $xml = @"





En.Book1.com
Ge.Book1.Com
Fr.Book1.com
Pl.Book1.com




"@

C:\PS> select-xml -content $xml -xpath "//edition"

Text Node Path
---- ---- ----
En.Book1.com edition InputStream
Ge.Book1.Com edition InputStream
Fr.Book1.com edition InputStream
Pl.Book1.com edition InputStream


C:\PS> $xml | select-xml -xpath "//edition"

Text Node Path
---- ---- ----
En.Book1.com edition InputStream
Ge.Book1.Com edition InputStream
Fr.Book1.com edition InputStream
Pl.Book1.com edition InputStream


Description
-----------
This example uses the Content parameter of Select-XML to search XML content in a here-string.

The first command saves the here-string in the $xml variable.

The second command uses the Content parameter to specify the XML in the $xml variable.

The third command is equivalent to the second. It uses a pipeline operator (|) to send the XML in the $xml variable
to the Select-XML cmdlet.

For more information about here-strings, type about_Quoting_Rules.






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=135255
ConvertTo-XML