$x = ([xml]"<sample name='notsample'/>").sample
Given the above line of code, as is, I want to find the name of the tag described by the XmlElement
in $x
. Typically, you would just use $x.Name
, but the name
attribute masks it. Instead of returning sample
, $x.name
returns notsample
.
The only workaround I've found is:
[Xml.XmlElement].GetProperty("Name").GetValue($x)
... but this is hacky. How can I do this correctly?
You can get it by invoking the property getter method directly:
$x.get_Name()
This works in many other similar cases. For example, if a type implements IDictonary
and has other properties, you may need to use this to access those properties. By default, PowerShell does a lookup into the dictionary rather than getting/setting the accessed property.
You can get PowerShell to show hidden members like these using the -Force
option on Get-Member
:
$x | gm -Force
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With