I'm trying to refer to some XML elements in a list of parent objects using Powershell, but when I reach the point in my variable declaration that includes a hyphen ('-') the rest of the declaration is read as an argument.
I've tried casting the variable name as a string, enclosing it in single and double quotes as well as parentheses. None have worked.
$imessagelist = $xml.pnet_message_history_packet_response.IMessage
$formidlist = $imessage.formdata.form_id
$fieldlist = $imessage.formdata.im_field
$fieldcontent = $field.data.data_numeric-enhanced
All the references like formidlist and fieldlist let me append '.formdata.im_field' to the list of items and retrieve the data. The only one that doesn't work is the one with a dash in it. The error received is as follows:
At C:\Temps-v0.1.ps1:36 char:69
+ ... $fieldcontent = $field.data.data_numeric-enhanced
+ ~~~~~~~~~
Unexpected token '-enhanced' in expression or statement.
I can't figure out how to escape the dash and get the value in the field named data_numeric-enhanced. Any advice would be very welcome!
$field.data.'data_numeric-enhanced'?