Displaying Original input from CSV in results Table

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Mark Prior Mark Prior 6 months, 2 weeks ago.

  • Author
    Posts
  • #40578
    Profile photo of Mark Prior
    Mark Prior
    Participant

    Hi All

    i have a csv, content like below

    mark.prior@contoso.com
    James.dean@contoso.com

    now when i pipe this to get-mailboxstatistics as below i get the expected result,

    {Pre} get-content "c:\temp\email2.csv" | Get-MailboxStatistics | Select DisplayName, database, LastLog* | Out-GridView
    {/pre}

    DisplayName Database etc...... etc.......
    ——————– ————- ———- ———

    Mark Prior blah
    James Dean blaa_1

    however i would like the original csv input posted alongside the generated result

    DisplayName Database etc...... etc....... Orignal Input
    ——————– ————- ———- ——— ——————–

    Mark Prior blah mark.prior@contoso.com
    James Dean blaa_1 James.dean@contoso.com

    thanks much guys

    p.s like the new forum

  • #40585
    Profile photo of Mark Prior
    Mark Prior
    Participant
    get-content "c:\temp\email2.csv" | Get-MailboxStatistics | Select DisplayName, database, LastLog* | Out-GridView

    dang cant edit original to correct code

  • #40589
    Profile photo of Dan Potter
    Dan Potter
    Participant
    $csv = import-csv "c:\temp\email2.csv"
    
    foreach($user in $csv){
    
    $mbxstats = Get-MailboxStatistics $user
    
    [pscustomobject]@{
    
    prop1 = $user.column1
    prop2 = $user.column1
    prop3 = $mbxstats.property1
    prop4 = $mbxstats.property2
    #etc..
    }
    
    }
    
    
    • #40624
      Profile photo of Mark Prior
      Mark Prior
      Participant

      great thanks, ended up using get-content as import-csv was erroring
      end script

      $csv = get-content "c:\temp\email1.csv"
      foreach($user in $csv){
      
      $mbxstats = Get-MailboxStatistics $user
      
      [pscustomobject]@{
      
      'Email Address' = $user
      'Database Location' = $mbxstats.DatabaseName
      'Last Accessed By' = $mbxstats.LastLoggedOnUserAccount
      'Last Logon Time' = $mbxstats.LastLogonTime
      } 
      
      }

      how would i output this to gridview ?

  • #40651
    Profile photo of Dan Potter
    Dan Potter
    Participant

    either assign variable before the foreach or pipe after the last bracket

    
    $csv = get-content "c:\temp\email1.csv"
    $output = foreach($user in $csv){
    
    $mbxstats = Get-MailboxStatistics $user
    
    [pscustomobject]@{
    
    'Email Address' = $user
    'Database Location' = $mbxstats.DatabaseName
    'Last Accessed By' = $mbxstats.LastLoggedOnUserAccount
    'Last Logon Time' = $mbxstats.LastLogonTime
    } 
    
    }
    
    $output | out-gridview
    
    
    $csv = get-content "c:\temp\email1.csv"
    foreach($user in $csv){
    
    $mbxstats = Get-MailboxStatistics $user
    
    [pscustomobject]@{
    
    'Email Address' = $user
    'Database Location' = $mbxstats.DatabaseName
    'Last Accessed By' = $mbxstats.LastLoggedOnUserAccount
    'Last Logon Time' = $mbxstats.LastLogonTime
    } 
    
    } | out-gridview
    
  • #40665
    Profile photo of Mark Prior
    Mark Prior
    Participant

    thanks dan thats great

You must be logged in to reply to this topic.