views:

54

answers:

1

Hi Folks,

I have a command that formats it's output in the form of CSV. I have a list of machine this command will run against using a foreach loop. in the below example $serverlist is automatically generated with an AD Query.

foreach ($server in $serverlist) {
 $outputlist = mycommand
 }

what I would like to do is somehow end up with objects from the resulting CSV so I can then only select certain objects for a report. However the only way I can see to do this is using import-csv, which only seems to want to work with files and not variable: ie.

Import-Csv output.csv | ft "HostName","TaskName" | 
   Where-object {$_.TaskName -eq 'Blah'}

I'd like to be able to have import-csv $outputlist instead. doing this causes import-csv to have a hissyfit :)

Can anyone point me in the right direction on how to achieve this?

Cheers

+3  A: 

The command you want is called ConvertFrom-CSV. The syntax is shown below.

NAME
    ConvertFrom-CSV

SYNOPSIS
    Converts object properties in comma-separated value (CSV) format into CSV
    versions of the original objects.

SYNTAX
    ConvertFrom-CSV [[-Delimiter] <char>] [-InputObject] <PSObject[]> [-Header <string[]>] [<CommonParameters>]
    ConvertFrom-CSV -UseCulture [-InputObject] <PSObject[]> [-Header <string[]>] [<CommonParameters>]
Josh Einstein
Perfect, thanks:)
Ben Short