Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-24
4
Medium Priority
?
1,274 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 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 24

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 71

Accepted Solution

by:
Qlemo earned 2000 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 24

Author Closing Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

926 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