header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
combining multiple queries in one line of a csv output file
Last Post 13 Jul 2010 07:00 AM by Presence. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kulikscoUser is Offline
New Member
New Member
Posts:7
Avatar

--
12 Jul 2010 10:11 AM
    I am trying to merge the data from multiple queries into the same line in an ouptut to csv file.

    say i have something like this:

    Add-PSSnapin Quest.ActiveRoles.ADManagement

    import-csv "D:\Scripts\batch_files\x500.csv" | % {

    get-mailbox $_.username | select DisplayName, @{Expression={$_.emailaddresses | ? {$_.proxyaddressstring -clike "*severstalco.com"} | select -ExpandProperty addressstring};Label="TargetAddress"}, PrimarySmtpAddress

    get-QADuser $_.username | select GivenName, sn, l

    } Export-Csv "D:\Scripts\batch_files\testing.csv" -NoTypeInformation

    how can i get this information to go into one line per user in a csv output file? if i use the method above i'm only getting the output from the first command.

    i tried assigning the query to variables but i couldn't figure out how to remove the line break at the end of the values.
    PresenceUser is Offline
    New Member
    New Member
    Posts:87
    Avatar

    --
    13 Jul 2010 07:00 AM
    import-csv "D:\Scripts\batch_files\x500.csv" | foreach {$QADUSER = get-QADuser $_.username; get-mailbox $_.username | select DisplayName, @{Expression={$_.emailaddresses | where {$_.proxyaddressstring -clike "*severstalco.com"} | select -ExpandProperty addressstring};Label="TargetAddress"}, PrimarySmtpAddress, @{n=GivenName; e={$QADUSER.GivenName}}, @{n="SN";e={$QADUSER.sn}}} Export-Csv "D:\Scripts\batch_files\testing.csv" -NoTypeInformation

    i think this would work...

    but i haven't tested it yet..

    basic premise is if you need to combine thing into one csv, you have to use aliases, combined with @{name="";Expression={}}...

    example
    import-csv whatever.csv | foreach { $user= Get-user $_.username; $mailbox = get-mailbox $_.username; get-qaduser $_.username | select name, @{n="Email"; e{$Mailbox.emailaddress}}, @{n="Title";e={$user.title}}}

    I hope the above script works, but if it doesn't work, it will at least give you a starting off point.

    Thanks.
    Pres
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer