Solved

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

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

776 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