Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #84 ConvertFrom-CSV

    Posted on March 25th, 2010 Jonathan Medd No comments

    Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the ConvertFrom-CSV cmdlet.

    What can I do with it?

    Convert a series of CSV style strings which have been generated by ConvertTo-CSV back into objects.

    Example:

    Retrieve a list of services beginning with the letter b and convert the object into CSV style strings, storing them into the variable $CSVStrings . Convert these back into objects.

    $CSVStrings = Get-Service | Where-Object{$_.Name -like 'b*'}
    | ConvertTo-CSV -NoTypeInformation
    $CSVStrings | Select-Object -First 1
    $CSVStrings | ConvertFrom-CSV

    You will notice that $CSVStrings contains the same data as for the example in ConvertTo-CSV , cut short for clarity. That variable is piped into ConvertFrom-CSV to change it back.

    ConvertFrom-CSV1

    How could I have done this in PowerShell 1.0?

    You could have used Import-CSV, but that would have read the information from a file.

    1000 things 1% better!

    Leave a reply