I have simplified the process so that anyone can reproduce it (in my script it is a problem within a workflow, no functions involved, therefore I can`t save these values in variables and then show them by console). The first thing is to use powershell ISE.
function AAA { $datum1 = New-Object -TypeName PSObject $datum1 | Add-Member -MemberType NoteProperty -Name ColumnA -Value "AA" $datum1 | Add-Member -MemberType NoteProperty -Name ColumnB -Value "BB" return $datum1 } function BBB { $datum2 = New-Object -TypeName PSObject $datum2 | Add-Member -MemberType NoteProperty -Name ColumnA -Value "AA" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnC -Value "CC" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnD -Value "DD" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnE -Value "EE" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnF -Value "FF" return $datum2 } AAA BBB
Output:
ColumnA ColumnB ------- ------- AA BB AA
Any idea why this happens?
EDIT: I have solved this "sh1t" in the following way
function AAA { $datum1 = New-Object -TypeName PSObject $datum1 | Add-Member -MemberType NoteProperty -Name Index -Value "1" $datum1 | Add-Member -MemberType NoteProperty -Name ColumnA -Value "AA" $datum1 | Add-Member -MemberType NoteProperty -Name ColumnB -Value "BB" $datum1 } function BBB { $datum2 = New-Object -TypeName PSObject $datum2 | Add-Member -MemberType NoteProperty -Name Index -Value "2" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnA -Value "AA" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnC -Value "CC" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnD -Value "DD" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnE -Value "EE" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnF -Value "FF" $datum2 } AAA |? {$_.Index -eq "1"} | FT BBB |? {$_.Index -eq "2"} | FT
Anyway, can someone explain what's going on? I would really like to understand the reason and look for related information
EDIT2: Reply to Palle Due,
it doesn't work at all for my scenario as it adds a bit more complexity.
Out-Host
is not an option. Example provided:
workflow Get-Report { param ([string[]]$computername) foreach -Parallel ($computer in $computername) { sequence { InlineScript { $AAA = Invoke-Command -ScriptBlock { $datum1 = New-Object -TypeName PSObject $datum1 | Add-Member -MemberType NoteProperty -Name Index -Value "1" $datum1 | Add-Member -MemberType NoteProperty -Name ColumnA -Value "AA" $datum1 | Add-Member -MemberType NoteProperty -Name ColumnB -Value "BB" return $datum1 } $AAA | Out-Host $BBB = Invoke-Command -ScriptBlock { $datum2 = New-Object -TypeName PSObject $datum2 | Add-Member -MemberType NoteProperty -Name Index -Value "2" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnA -Value "AA" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnC -Value "CC" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnD -Value "DD" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnE -Value "EE" $datum2 | Add-Member -MemberType NoteProperty -Name ColumnF -Value "FF" return $datum2 } $BBB | Out-Host } #endinlinescript } #endsequence } #endforeach } #endWF $results = @() $results = Get-Report -Verbose -Computer "localhost","localhost" $results | FT
ColumnB
property to$datum2
that gets shown as well. If you call BBB AAA, you get the expected output, but not as a table. – Palle Due