Solved

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

Posted on 2014-10-24
4
880 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 84

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 22

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 69

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 22

Author Closing Comment

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Synchronize a new Active Directory domain with an existing Office 365 tenant
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

828 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