Both objects are being output, and the ISE is trying to show both of them to you. Here’s what’s going on as I understand it (I may be off on a few details, so anybody can feel free to correct me where I’m wrong):
- You create your first object, and it has three properties: Name, SID, and UPN
- Since it's not being captured, it needs to go to the screen. PowerShell's formatting rules kick in, and the object is inspected. It has less than five properties, so it decides to format it as a table.
- Since it's going to be formatted as a table, the headers have to be written first. The headers are written using the properties that were discovered in the last step.
- The first object is written to the host (all three properties are shown)
- The second object is created, and it has three properties: NValue, SValue, and UValue
- It needs to go to the screen. The formatting system is all geared up to write the output as a table with Name, SID, and UPN properties.
- The formatting system checks the Name, SID, and UPN properties of the second object; they don't exist, so it outputs null. The other three properties aren't shown because the table wasn't set up for them.
Here are a few ways to demonstrate what I’m talking about. There have been a lot of different ways to create objects in this thread, so I’m going to use my favorite (it requires PSv3 or higher):
$Output = @(
Name = "Name 1"
SID = "SID 1"
UPN = "UPN 1"
NValue = "Name 2"
SValue = "SID 2"
UValue = "UPN 2"
Name = "Name 3"
SID = "SID 3"
UValue = "UPN 3"
And here’s how it looks from the command line:
# Notice the blank line where the second object should be:
PS C:\> $Output
Name SID UPN
++++ +++ +++
Name 1 SID 1 UPN 1
Name 3 SID 3
# Here's what it looks like when you tell Format-Table all of the columns
# to show:
PS C:\> $Output | ft Name, SID, UPN, NValue, SValue, UValue
Name SID UPN NValue SValue UValue
++++ +++ +++ ++++++ ++++++ ++++++
Name 1 SID 1 UPN 1
Name 2 SID 2 UPN 2
Name 3 SID 3 UPN 3
So, your data is all there, it’s just not being shown because the objects are so different.