export to one CSV with multiple headings

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
  • #6498

    by sipho at 2012-12-20 12:00:12


    I am new to powershell and I can sort of modify scripts but my current task I feel is way out of my league..
    I have two power shell script and they are:

    import-csv input.csv | Get-MailboxStatistics | ft DisplayName, TotalItemSize, ItemCount -auto > C:\Logs\logs.csv
    import-csv input.csv | Get-mailbox |select RecipientTypeDetails, displayname, IssueWarningQuota|export-csv C:\Logs\logs.csv -NoTypeInformation

    How do I get the information that I require from both these scripts into 1 single CSV called logs.csv .....the input.csv contains the same info which is the SMTP address of the users with A1 as identity.
    I want to join both these scripts into one...just not sure how to pipe that...



    by DonJ at 2012-12-20 13:57:17

    CSV isn't designed to do that, and the resulting file would not be a valid CSV. The problem is that your two commands are creating different output; CSV assumes that every line will contain the exact same columns.

    If you simply want to jam the second set of CSV information at the end of the first...

    import-csv input.csv | Get-mailbox |select RecipientTypeDetails, displayname, IssueWarningQuota|convertto-csv >> C:\Logs\logs.csv

    But there's no way to make that a valid CSV file.

    by ArtB0514 at 2012-12-21 11:03:24

    On the other hand, you can create a single CSV with data from two different queries. Basically, you create a new object type and load it from both queries.

    Import-CSV Input.csv | foreach {
    $stat = Get-MailboxStatistics $_. | Select DisplayName, TotalItemSize, ItemCount
    $mbx = Get-mailbox $_.
    |select RecipientTypeDetails, displayname, IssueWarningQuota
    $MergedData = New-Object PSObject -Property @{
    'DisplayName' = $stat.DisplayName
    'Size' = $stat.TotalItemSize
    'Count' = $stat.ItemCount
    'Type' = $mbx.RecipientTypeDetails
    'Warning' = $mbx.IssueWarningQuota
    $MergedData | Export-Csv C:\Logs\logs.csv -NoTypeInformation

You must be logged in to reply to this topic.