Solved

When Export-CSV I get #TYPE System.Object[]

Posted on 2014-10-24
4
733 Views
Last Modified: 2014-10-24
I have a simple three step Powershell that runs two commands then concatenates them to one array.
When I run it without the Export-CSV it looks fine, but when I add the Export-CSV I get.

#TYPE System.Object[]
"Count","Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized"
"26","26","26","1","System.Object[]","False","True","False"
"313","313","313","1","System.Object[]","False","True","False"

I can run each command individually and successfully export-csv against each step.

$A = @()
$b = @()
$A = @(Get-BEJob |Where {$_.Name -like '*full'} | Select Name,NextStartDate)
$b =  @(Get-BEJob |Where {$_.Name -like '*full'}| Get-BEJobHistory |  Select Name,Jobstatus,Starttime,endtime)

$c = $a,$b 
$C |Export-csv  C:\c.txt

Open in new window

0
Comment
Question by:yo_bee
  • 2
4 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 40401923
Add -NoTypeInformation (or -NTI) to the Export-Csv options:
$C |Export-csv  C:\c.txt -NoTypeInformation

Open in new window

0
 
LVL 21

Author Comment

by:yo_bee
ID: 40402001
I did that and I still got the output of

#TYPE System.Object[]
 "Count","Length","LongLength","Rank","SyncRoot","IsReadOnly","IsFixedSize","IsSynchronized"
 "26","26","26","1","System.Object[]","False","True","False"
 "313","313","313","1","System.Object[]","False","True","False"
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40402030
That's not the only issue:
You are trying to combine two arrays consisting of different object types with different properties. That will never be formatted or exported correctly, as all such cmdlets use the first element of arrays to determine what properties exists, and other properties are dismissed on output. That means even if you succeeded in exporting the content, you would see $a, followed by $b with the only common property Name.

In the sequence of
$A = @()
$b = @()
$A = @(some-command)
$b = @(some-command)

Open in new window

the first two lines are superfluous. You are creating empty arrays, and overwrite them with results. Just omit the init.

You are nesting arrays instead of combining, what probably has been your target.
$c[0] is $A, $c[1] is $b. Doing that is fine if you treat the elements differently, and only want to pass them within a single var, but certainly that was not your intention here.

You are repeating the same command, just to process it differently. Usually it is a better idea to store the result of the repeated command, and then process it.

You should either export each result (a and b) to different files, or mix the info for both into a single line per entry. So my suggestion is to use
Get-BEJob |Where {$_.Name -like '*full'} | % {
  $beJob = $_
  $beJob | Get-BEJobHistory |
    select Name, 
           @{n = 'NextStartDate'; e = {$beJob.NextStartDate}},
           JobStatus, StartTime, EndTime
} | Export-csv -NoType  C:\c.txt

Open in new window

0
 
LVL 21

Author Closing Comment

by:yo_bee
ID: 40402090
This worked perfectly.
Thanks  for your help
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Not needed 13 58
last logon 2 16
Powershell 16 32
What language/protocol is the Angular Chat? 2 16
Utilizing an array to gracefully append to a list of EmailAddresses
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now