Import CSV from variable instead of file?

I have a command that formats its output as CSV. I have a list of machines that this command will work against using a foreach loop. in the example below, $ serverlist is automatically created using AD Query.

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

what I would like to do somehow ends up with objects from the resulting CSV, so I can only select specific objects for the report. However, the only way I can do this is to use import-csv, which seems to only want to work with files, not variables: ie.

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

I would like to have an import-csv $ list instead. this causes import-csv to have a synonym :)

Can someone point me in the right direction how to do this?

Greetings

+4
source share
1 answer

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>]
+9
source

All Articles