PowerShellCookbook icon indicating copy to clipboard operation
PowerShellCookbook copied to clipboard

If a property begins with a '#' character, this kills Show-object

Open 1RedOne opened this issue 10 years ago • 0 comments

Found a weird one.

[xml]$xml = wget https://patchmypc.net/category/SCUPCatalogChanges/feed Show-Object $xml

This object has a property which is named '#comments', and Show-object runs into the following error when trying to parse this:

Invoke-Expression : At line:1 char:20

  • $resultObject = $a.#comment
  •                ~
    
    Missing property name after reference operator. At C:\Program Files\WindowsPowerShell\Modules\PowerShellCookbook\1.3.3\PowerShellCookbook.psm1:7648 char:9
  •     Invoke-Expression "`$resultObject = $nodePath"
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
    • FullyQualifiedErrorId : MissingPropertyName,Microsoft.PowerShell.Commands.InvokeExpressionCommand

The variable '$resultObject' cannot be retrieved because it has not been set. At C:\Program Files\WindowsPowerShell\Modules\PowerShellCookbook\1.3.3\PowerShellCookbook.psm1:7651 char:36

  •     PopulateNode $selectedNode $resultObject
    
  •                                ~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (resultObject:String) [], RuntimeException
    • FullyQualifiedErrorId : VariableIsUndefined

The code in question

## Walk through its parents, creating the virtual
        ## PowerShell syntax to access this property.
        $nodePath = GetPathForNode $selectedNode 

        ## Now, invoke that PowerShell syntax to retrieve
        ## the value of the property.
        Invoke-Expression "`$resultObject = $nodePath"

        ## And populate the node with the result object.
        PopulateNode $selectedNode $resultObject

1RedOne avatar Nov 17 '15 20:11 1RedOne