< Back

Invoke-XpathQuery

Sat Jan 18, 2020 9:14 pm

NAME Invoke-XpathQuery



SYNOPSIS

Invoke-XpathQuery provides a consistent way of performing xpath queries on

XML element and document nodes on both Desktop and Core PowerShell editions.





SYNTAX

Invoke-XpathQuery [-QueryMethod] <String> [-Node] <Object> [-query] <String> [<CommonParameters>]





DESCRIPTION

Invoke-XpathQuery is required because of the differing XPath implementations

in the dotnet FullCRL on Desktop and the dotNet Core CLR on Core editions of

PowerShell.



The is typcially only utilised internally by PowerNSX cmdlets, but is

exported by the PowerNSX module to provide the same capability to anyone

who needs to manipulate XML in scripts that consume PowerNSX without having

to manually copy the function out of the PowerNSX code in order to leverage

it for cross platform support.



It is highly likely that if you dont know why you need this cmdlet, then you

dont need it :)





PARAMETERS

-QueryMethod <String>

XPath query method. Supports SelectSingleNode or SelectNodes.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Node <Object>

XmlDocument or XmlElement node to be queried.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-query <String>

Xpath Query.



Required? true

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



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



PS C:\\>$NodeToRemove = (Invoke-XPathQuery -QueryMethod SelectSingleNode -Node $xmlnode -Query

"descendant::subInterface[index=0]")



returns a single XML node matching the specified XPATH query.









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



PS C:\\>$NodeToRemove = (Invoke-XPathQuery -QueryMethod SelectNodes -Node $xmlnode -Query

"descendant::subInterface")



returns a collection of XML nodes matching the specified XPATH query.











RELATED LINKS