diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs
index b9c4e2d454a..48d84636ce2 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WriteConsoleCmdlet.cs
@@ -4,6 +4,7 @@
using System.Collections;
using System.Management.Automation;
using System.Text;
+using System.Xml;
namespace Microsoft.PowerShell.Commands
{
@@ -59,6 +60,10 @@ private string ProcessObject(object o)
return s;
}
}
+ else if (o is XmlNode xmlNode)
+ {
+ return xmlNode.Name;
+ }
else if (o is IEnumerable enumerable)
{
// unroll enumerables, including arrays.
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1
index a75c17bcbaa..92b6a027853 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Host.Tests.ps1
@@ -60,6 +60,8 @@ Describe "Write-Host with TestHostCS" -Tags "CI" {
@{ Name = '-Separator, colors and -NoNewLine'; Command = "Write-Host a,b,c -Separator ',' -ForegroundColor Yellow -BackgroundColor DarkBlue -NoNewline"; returnCount = 1; returnValue = @("Yellow:DarkBlue:a,b,c:NoNewLine"); returnInfo = @("a,b,c") }
@{ Name = '-NoNewline:$true and colors'; Command = "Write-Host a,b -NoNewline:`$true -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NoNewLine", "White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
@{ Name = '-NoNewline:$false and colors'; Command = "Write-Host a,b -NoNewline:`$false -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NewLine","White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
+ @{ Name = 'XMLElement'; Command = "Write-Host ([xml] 'Where art thou?').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }
+ @{ Name = 'XMLDocument'; Command = "Write-Host ([system.xml.xmldocument] 'Where art thou?').DocumentElement"; returnCount = 1; returnValue = @("White:Black:OhElement:NewLine"); returnInfo = @("OhElement") }
)
}