-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Resolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Description
When setting an XML node content, PowerShell doesn't correctly unwrap PSObject strings.
For instance: Join-Path obviously outputs strings, but it outputs them wrapped in PSObjects
Steps to reproduce
[xml]$x = "<root><path/></root>"
$x.root.path = Join-Path C:\ WindowsExpected behavior
$x.root.path is an XML Node with string content "C:\Windows"
Actual behavior
A SetValueException is thrown:
Cannot set "path" because only strings can be used as values to set XmlNode properties.
At line:2 char:1
+ $x.root.path = Join-Path C:\ Windows
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], SetValueException
+ FullyQualifiedErrorId : XmlNodeSetShouldBeAString
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.206
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.206
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Workaround
Either of the following would work, but should not be necessary:
$x.root.path = (Join-Path C:\ Windows).PSObject.BaseObject
$x.root.path = (Join-Path C:\ Windows).ToString()djohnst10 and ajruckman
Metadata
Metadata
Assignees
Labels
Resolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime