0

I've created a custom object and tried to print out the object:

$longest_common_entry= New-Object System.Object
$longest_common_entry | Add-Member -type NoteProperty -name s1 -Value $mytext[0]
$longest_common_entry | Add-Member -type NoteProperty -name s2 -Value $mytext[1]
$longest_common_entry | Add-Member -type NoteProperty -name lcs -Value ""
$longest_common_entry | Add-Member -type NoteProperty -name lcs_length -Value 0

Write-Host $longest_common_entry
System.Object

Write-Output $longest_common_entry<BR>
s1 s2 lcs lcs_length
-- -- --- ----------
"Report Technical Design 0.4.docx" "Report Technical Design 0.3.docx" "" 0

Why does write-output displays the object content but not write-host?

phillip-from-oz
  • 352
  • 1
  • 5
  • 16
  • Because write host is using the ToString() method of your object. It does not know how to display it as a flat string. Write-Output is object aware. – Matt Oct 23 '17 at 00:35
  • 1
    Look at this answer for more detail: https://stackoverflow.com/a/45829541/3829407 – Matt Oct 23 '17 at 00:36

0 Answers0