Solved

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

Posted on 2014-10-24
4
1,071 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85

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 23

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 70

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 23

Author Closing Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

627 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