Category Archives: Csv

Import-Csv

NAME
    Import-Csv

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

SYNTAX
    Import-Csv [[-Delimiter] <char>] [-Path] <string[]> [-Header <string[]>] [<CommonParameters>]

    Import-Csv -UseCulture [-Path] <string[]> [-Header <string[]>] [<CommonParameters>]

DESCRIPTION
    The Import-Csv cmdlet creates objects from CSV Variable-length files that are generated by the Export-Csv cmdlet.

    You can use the parameters of the Import-Csv cmdlet to specify the column header row, which determines the property names of the resulting objects; to specify the item delimiter; or to direct Import-Csv to use the list separator for the current culture as the item delimiter.

    The objects that Import-Csv creates are CSV versions of the original objects. The property values of the CSV objects are string versions of the property values of the original objects. The CSV versions of the objects do not have any methods.

    You can also use the ConvertTo-Csv and ConvertFrom-Csv cmdlets to convert objects to CSV strings (and back). These cmdlets are the same as the Export-Csv and Import-Csv cmdlets, except that they do not save the CSV strings in a file.

PARAMETERS
    -Delimiter <char>
        Specifies the delimiter that separates the property values in the CSV file. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in quotation marks.

        If you specify a character other than the actual string delimiter in the file, Import-Csv cannot create objects from the CSV strings. Instead, it returns the strings.

        Required?                    false
        Position?                    2
        Default value                ,
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Header <string[]>
        Specifies an alternate column header row for the imported file. The column header determines the names of the properties of the object that Import-Csv creates.

        Enter a comma-separated list of the column headers. Enclose each item in quotation marks (single or double). Do not enclose the header string in quotation marks. If you enter fewer column headers than there are columns, the remaining columns will have no header. If you enter more headers than there are columns, the extra headers are ignored.

        When using the Header parameter, delete the original header row from the CSV file. Otherwise, Import-Csv creates an extra object from the items in the header row.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string[]>
        Specifies the path to the CSV file to import. You can also pipe a path to Import-Csv.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -UseCulture [<SwitchParameter>]
        Use the list separator for the current culture as the item delimiter. The default is a comma (,).

        To find the list separator for a culture, use the following command: (Get-Culture).TextInfo.ListSeparator. If you specify a character other than the delimiter used in the CSV strings, ConvertFrom-Csv cannot create objects from the CSV strings. Instead, it returns the strings.

        Required?                    true
        Position?                    named
        Default value                Comma
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe a string that contains a path to Import-Csv.

OUTPUTS
    Object.
        Import-Csv returns the objects described by the content in the CSV file.

NOTES

        Because the imported objects are CSV versions of the object type, they are not recognized and formatted by the Windows PowerShell type formatting entries that format the non-CSV versions of the object type.

        In the CSV file, each object is represented by a comma-separated list of the property values of the object. The property values are converted to strings (by using the ToString() method of the object), so they are generally represented by the name of the property value. Export-Csv does not export the methods of the object.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv

    C:\PS> $p = Import-Csv processes.csv

    C:\PS> $p | Get-Member

     TypeName: CSV:System.Diagnostics.Process

    Name                     MemberType Definition
    —-                     ———- ———-
    Equals                     Method     System.Boolean Equals(Object obj)
    GetHashCode                Method     System.Int32 GetHashCode()
    GetType                    Method     System.Type GetType()
    ToString                 Method     System.String ToString()
    BasePriority             NoteProperty System.String BasePriority=8
    Company                    NoteProperty System.String Company=Microsoft Corporation
    …

    C:\PS> $p | Out-GridView

    Description
    ———–
    This example shows how to export and then import a CSV file of Microsoft .NET Framework objects.

    The first command uses the Get-Process cmdlet to get the process on the local computer. It uses a pipeline operator (|) to send the process objects to the Export-Csv cmdlet, which exports the process objects to the Processes.csv file in the current directory.

    The second command uses the Import-Csv cmdlet to import the processes in the Import-Csv file. Then it saves the resulting process objects in the $p Variable.

    The third command uses a pipeline operator to pipe the imported objects to the Get-Member cmdlets. The result shows that they are CSV:System.Diagnostic.Process objects, not the System.Diagnostic.Process objects that Get-Process returns.

    Also, because there is no entry type in the formatting files for the CSV version of the process objects, these objects are not formatted in the same way that standard process objects are formatted.

    To display the objects, use the formatting cmdlets, such as Format-Table and Format-List, or pipe the objects to Out-GridView.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -Delimiter :

    C:\PS> $p = Import-Csv processes.csv -Delimiter :

    Description
    ———–
    This example shows how to use the Delimiter parameter of Import-Csv. In this example, the processes are exported to a file that uses a colon (:) as a delimiter.

    When importing, the Import-Csv file uses the Delimiter parameter to indicate the delimiter that is used in the file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$p = Import-Csv processes.csv -UseCulture

    C:\PS> (Get-Culture).textinfo.listseparator

    ,

    Description
    ———–
    This example shows how to use the UseCulture parameter of Import-Csv.

    The first command imports the objects in the Processes.csv file into the $p Variable. It uses the UseCulture parameter to direct Import-Csv to use the list separator defined for the current culture.

    The second command displays the list separator for the current culture. It uses the Get-Culture cmdlet to get the current culture. It uses the dot (.) method to get the TextInfo property of the current culture and the ListSeparator property of the object in TextInfo. In this example, the command returns a comma.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Start-Job -scriptblock { Get-Process } | Export-Csv jobs.csv

    C:\PS> $header = “MoreData”,”StatusMessage”,”Location”,”Command”,”State”,”Finished”,”InstanceId”,”SessionId”,”Name”,”ChildJobs”,”Output”,”Error”,”Progress”,”Verbose”,”Debug”,”Warning”,”StateChanged”

    # Delete header from file
    C:\PS> $a = (Get-Content jobs.csv)
    C:\PS> $a = $a[0], $a[2..($a.count – 1)]
    C:\PS> $a > jobs.csv

    C:\PS> $j = Import-Csv jobs.csv -Header $header

    C:\PS> $j

    MoreData     : True
    StatusMessage :
    Location     : localhost
    Command     : Get-Process
    State         : Running
    Finished     : System.Threading.ManualResetEvent
    InstanceId    : 135bdd25-40d6-4a20-bd68-05282a59abd6
    SessionId     : 1
    Name         : Job1
    ChildJobs     : System.Collections.Generic.List`1[System.Management.Automation.Job]
    Output        : System.Management.Automation.PSDataCollection`1[System.Management.Automation.PSObject]
    Error         : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ErrorRecord]
    Progress     : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ProgressRecord]
    Verbose     : System.Management.Automation.PSDataCollection`1[System.String]
    Debug         : System.Management.Automation.PSDataCollection`1[System.String]
    Warning     : System.Management.Automation.PSDataCollection`1[System.String]
    StateChanged :

    Description
    ———–
    This example shows how to use the Header parameter of Import-Csv to change the names of properties in the resulting imported object.

    The first command uses the Start-Job cmdlet to start a background job that runs a Get-Process command on the local computer. A pipeline operator (|) sends the resulting job object to the Export-Csv cmdlet, which converts the job object to CSV format. An assignment operator (=) saves the resulting CSV in the Jobs.csv file.

    The second command saves a header in the $header Variable. Unlike the default header, this header uses “MoreData” instead of “HasMoreData” and “State” instead of “JobStateInfo”.

    The next three commands delete the original header (the second line) from the Jobs.csv file.

    The sixth command uses the Import-Csv cmdlet to import the Jobs.csv file and convert the CSV strings into a CSV version of the job object. The command uses the Header parameter to submit the alternate header. The results are stored in the $j Variable.

    The seventh command displays the object in the $j Variable. The resulting object has “MoreData” and “State” properties, as shown in the command output.

    ————————– EXAMPLE 5 ————————–

    C:\PS>”.\processes.csv” | Import-Csv

    Description
    ———–
    This command imports the objects from the Processes.csv file.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113341
    Export-Csv
    ConvertTo-Csv
    ConvertFrom-Csv

Export-Csv

NAME
    Export-Csv

SYNOPSIS
    Converts Microsoft .NET Framework objects into a series of comma-separated value (CSV) Variable-length strings and saves the strings in a CSV file.

SYNTAX
    Export-Csv [[-Delimiter] <char>] [-Path] <string> -InputObject <psobject> [-Encoding <string>] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf] [<CommonParameters>]

    Export-Csv [-UseCulture] [-Path] <string> -InputObject <psobject> [-Encoding <string>] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Export-Csv cmdlet creates a CSV Variable-length file that represents the objects that you submit.
    You can then use the Import-Csv cmdlet to re-create objects from the CSV strings in the files. The resulting objects are CSV versions of the original objects that consist of string representations of the property values and no methods.

    You can also use the ConvertTo-Csv and ConvertFrom-Csv cmdlets to convert .NET Framework objects to CSV strings (and back). Export-Csv is the same as ConvertTo-Csv, except that it saves the CSV strings in a file.

    You can use the parameters of the Export-Csv cmdlet to specify a delimiter other than a comma or to direct Export-Csv to use the default delimiter for the current culture.

    When you submit multiple objects to Export-Csv, Export-Csv organizes the file based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is null, as represented by two consecutive commas. If the remaining objects have additional properties, those property values are not included in the file.

    For more information, see Export-Csv, and see the Notes section.

PARAMETERS
    -Delimiter <char>
        Specifies a delimiter to separate the property values. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in quotation marks.

        Required?                    false
        Position?                    2
        Default value                , (comma)
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Encoding <string>
        Specifies the encoding for the exported CSV file. Valid values are Unicode, UTF7, UTF8, ASCII, UTF32, BigEndianUnicode, Default, and OEM. The default is ASCII.

        Required?                    false
        Position?                    named
        Default value                ASCII
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force [<SwitchParameter>]
        Overwrites the file specified in path without prompting.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the objects to export as CSV strings. Enter a Variable that contains the objects or type a command or expression that gets the objects. You can also pipe objects to Export-Csv.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -NoClobber [<SwitchParameter>]
        Do not overwrite (replace the contents) of an existing file. By default, if a file exists in the specified path, Export-Csv overwrites the file without warning.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -NoTypeInformation [<SwitchParameter>]
        Omits the type information from the CSV file. By default, the first line of the CSV file contains “#TYPE ” followed by the fully-qualified name of the type of the .NET Framework object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string>
        Specifies the path to the CSV output file. The parameter is required.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -UseCulture [<SwitchParameter>]
        Use the list separator for the current culture as the item delimiter. The default is a comma (,).

        This parameter is very useful in scripts that are being distributed to users worldwide. To find the list separator for a culture, use the following command: (Get-Culture).TextInfo.ListSeparator.

        Required?                    false
        Position?                    named
        Default value                Comma
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe any .NET Framework object to Export-Csv.

OUTPUTS
    System.String
        The CSV list is sent to the file designated in the Path parameter.

NOTES

        The Export-Csv cmdlet converts the objects that you submit into a series of CSV Variable-length strings and saves them in the specified text file. You can use Export-Csv to save objects in a CSV file and then use the Import-Csv cmdlet to create objects from the text in the CSV file.

        In the CSV file, each object is represented by a comma-separated list of the property values of the object. The property values are converted to strings (by using the ToString() method of the object), so they are generally represented by the name of the property value. Export-Csv does not export the methods of the object.

        The format of an exported file is as follows:
        — The first line of the CSV file contains the string ‘#TYPE ‘ followed by the fully qualified name of the .NET Framework type of the object, such as #TYPE System.Diagnostics.Process. To suppress this line, use the NoTypeInformation parameter.

        — The next line of the CSV file represents the column headers. It contains a comma-separated list of the names of all the properties of the first object.

        — Additional lines of the file consist of comma-separated lists of the property values of each object.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Process wmiprvse | Select-Object basePriority,ID,SessionID,WorkingSet | Export-Csv -Path data.csv

    Description
    ———–
    This command selects a few properties of the wmiprvse process and exports them to a CSV format file named data.csv.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv

    C:\PS> Get-Process | Export-Csv processes.csv

    # In processes.csv

    #TYPE System.Diagnostics.Process
    __NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,…
    Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS…
    Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\…

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. Because it does not specify a delimiter, a comma (,) is used to separate the fields in the file.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -Delimiter “;”

    # In processes.csv

    #TYPE System.Diagnostics.Process
    __NounName;Name;Handles;VM;WS;PM;NPM;Path;Company;CPU;FileVersion;…
    Process;powershell;626;201666560;76058624;61943808;11960;C:\WINDOWS…
    Process;powershell;257;151920640;38322176;37052416;7836;C:\WINDOWS\…

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the Delimiter parameter to specify the semicolon (;). As a result, the fields in the file are separated by semicolons.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -UseCulture

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the UseCulture parameter to direct Export-Csv to use the delimiter specified by the ListSeparator property of the current culture.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Process | Export-Csv processes.csv -NoTypeInformation

    C:\PS> Get-Process | Export-Csv processes.csv -NoTypeInformation

    # In processes.csv

    __NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,…
    Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS…
    Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\…

    Description
    ———–
    This command exports objects representing the processes on the computer to the Processes.csv file in the current directory. It uses the NoTypeInformation parameter to suppress the type information in the file.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113299
    Import-Csv
    ConvertTo-Csv
    ConvertFrom-Csv

ConvertTo-Csv

NAME
    ConvertTo-Csv

SYNOPSIS
    Converts Microsoft .NET Framework objects into a series of comma-separated value (CSV) Variable-length strings.

SYNTAX
    ConvertTo-Csv [[-Delimiter] <char>] [-InputObject] <psobject> [-NoTypeInformation] [<CommonParameters>]

    ConvertTo-Csv [-UseCulture] [-InputObject] <psobject> [-NoTypeInformation] [<CommonParameters>]

DESCRIPTION
    The ConvertTo-Csv cmdlet returns a series of comma-separated, Variable-length (CSV) strings that represents the objects that you submit. You can then use the ConvertFrom-Csv cmdlet to re-create objects from the CSV strings. The resulting objects are CSV versions of the original objects that consist of string representations of the property values and no methods.

    You can also use the Export-Csv and Import-Csv cmdlets to convert .NET Framework objects to CSV strings (and back). Export-Csv is the same as ConvertTo-Csv, except that it saves the CSV strings in a file.

    You can use the parameters of the ConvertTo-Csv cmdlet to specify a delimiter other than a comma or to direct ConvertTo-Csv to use the default delimiter for the current culture.

    For more information, see Export-Csv, and see the Notes section.

PARAMETERS
    -Delimiter <char>
        Specifies a delimiter to separate the property values. The default is a comma (,). Enter a character, such as a colon (:).

        To specify a semicolon (;), enclose it in quotation marks. Otherwise, it will be interpreted as the command delimiter.

        Required?                    false
        Position?                    2
        Default value                , (comma)
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the objects to export as CSV strings. Enter a Variable that contains the objects or type a command or expression that gets the objects. You can also pipe objects to ConvertTo-Csv.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -NoTypeInformation [<SwitchParameter>]
        Omits the type information header from the output. By default, the string in the output contains “#TYPE ” followed by the fully-qualified name of the type of the .NET Framework object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -UseCulture [<SwitchParameter>]
        Uses the list separator for the current culture as the data delimiter. The default is a comma (,).

        This parameter is very useful in scripts that are being distributed to users worldwide. To find the list separator for a culture, use the following command: (Get-Culture).TextInfo.ListSeparator.

        Required?                    false
        Position?                    named
        Default value                Comma
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe any .NET Framework object to ConvertTo-Csv.

OUTPUTS
    System.String
        The CSV output is returned as a collection of strings.

NOTES

        In CSV format, each object is represented by a comma-separated list of its property value. The property values are converted to strings (by using the ToString() method of the object), so they are generally represented by the name of the property value. ConvertTo-Csv does not export the methods of the object.

        The format of the resulting CSV strings is as follows:

        — The first string consists of ‘#TYPE ‘ followed by the fully-qualified name of the .NET Framework type of the object, such as #TYPE System.Diagnostics.Process. To suppress this string, use the NoTypeInformation parameter.

        — The next string represents the column headers. It contains a comma-separated list of the names of all the properties of the first object.

        — The remaining strings consist of comma-separated lists of the property values of each object.

        When you submit multiple objects to ConvertTo-Csv, ConvertTo-Csv orders the strings based on the properties of the first object that you submit. If the remaining objects do not have one of the specified properties, the property value of that object is null, as represented by two consecutive commas. If the remaining objects have additional properties, those property values are ignored.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Process powershell | ConvertTo-Csv

    #TYPE System.Diagnostics.Process
    “__NounName”,”Name”,”Handles”,”VM”,”WS”,”PM”,”NPM”,”Path”,”Company”,”CPU”,”FileVersion”,”ProductVersion”,”Description”,
    “Product”,”BasePriority”,”ExitCode”,”HasExited”,”ExitTime”,”Handle”,”HandleCount”,”Id”,”MachineName”,”MainWindowHandle”
    ,”MainWindowTitle”,”MainModule”,”MaxWorkingSet”,”MinWorkingSet”,”Modules”,”NonpagedSystemMemorySize”,”NonpagedSystemMem
    orySize64″,”PagedMemorySize”,”PagedMemorySize64″,”PagedSystemMemorySize”,”PagedSystemMemorySize64″,”PeakPagedMemorySize
    “,”PeakPagedMemorySize64″,”PeakWorkingSet”,”PeakWorkingSet64″,”PeakVirtualMemorySize”,”PeakVirtualMemorySize64″,”Priori
    tyBoostEnabled”,”PriorityClass”,”PrivateMemorySize”,”PrivateMemorySize64″,”PrivilegedProcessorTime”,”ProcessName”,”Proc
    essorAffinity”,”Responding”,”SessionId”,”StartInfo”,”StartTime”,”SynchronizingObject”,”Threads”,”TotalProcessorTime”,”U
    serProcessorTime”,”VirtualMemorySize”,”VirtualMemorySize64″,”EnableRaisingEvents”,”StandardInput”,”StandardOutput”,”Sta
    ndardError”,”WorkingSet”,”WorkingSet64″,”Site”,”Container”
    “Process”,”powershell”,”216″,”597544960″,”60399616″,”63197184″,”21692″,”C:\WINDOWS\system32\WindowsPowerShell\v1.0\powe
    rshell.exe”,”Microsoft Corporation”,”3.4788223″,”6.1.6587.1 (fbl_srv_powershell(nigels).070711-0102)”,”6.1.6587.1″,”Win
    dows PowerShell”,”Microsoft® Windows® Operating System”,”8″,,”False”,,”860″,”216″,”5132″,”.”,”5636936″,”Windows PowerSh
    ell 2.0 (04/17/2008 00:10:40)”,”System.Diagnostics.ProcessModule (powershell.exe)”,”1413120″,”204800″,”System.Diagnosti
    cs.ProcessModuleCollection”,”21692″,”21692″,”63197184″,”63197184″,”320080″,”320080″,”63868928″,”63868928″,”60715008″,”6
    0715008″,”598642688″,”598642688″,”True”,”Normal”,”63197184″,”63197184″,”00:00:00.2028013″,”powershell”,”15″,”True”,”1″,
    “System.Diagnostics.ProcessStartInfo”,”4/21/2008 3:49:19 PM”,,”System.Diagnostics.ProcessThreadCollection”,”00:00:03.51
    00225″,”00:00:03.3072212″,”597544960″,”597544960″,”False”,,,,”60399616″,”60399616″,,

    Description
    ———–
    This command converts a single process object to CSV format. The command uses the Get-Process cmdlet to get the PowerShell process on the local computer. It uses a pipeline operator (|) to send the command to the ConvertTo-Csv cmdlet, which converts it to a series of comma-separated strings.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$date = Get-Date

    C:\PS> ConvertTo-Csv -InputObject $date -Delimiter “;” -NoTypeInformation

    Description
    ———–
    This example converts a date object to CSV format.

    The first command uses the Get-Date cmdlet to get the current date. It saves it in the $date Variable.

    The second command uses the ConvertTo-Csv cmdlet to convert the DateTime object in the $date Variable to CSV format. The command uses the InputObject parameter to specify the object to be converted. It uses the Delimiter parameter to specify the delimiter that separates the object properties. It uses the NoTypeInformation parameter to suppress the #TYPE string.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-Eventlog -log “windows powershell” | ConvertTo-Csv -useculture

    Description
    ———–
    This command converts the Windows PowerShell event log on the local computer to a series of CSV strings.

    The command uses the Get-EventLog cmdlet to get the events in the Windows PowerShell log. A pipeline operator (|) sends the events to the ConvertTo-Csv cmdlet, which converts the events to CSV format. The command uses the UseCulture parameter, which uses the list separator for the current culture as the delimiter.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135203
    Import-Csv
    Export-Csv
    ConvertFrom-Csv

ConvertFrom-Csv

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>]

DESCRIPTION
    The ConvertFrom-Csv cmdlet creates objects from CSV Variable-length strings that are generated by the ConvertTo-Csv cmdlet.

    You can use the parameters of the ConvertFrom-Csv cmdlet to specify the column header row, which determines the property names of the resulting objects, to specify the item delimiter, or to direct ConvertFrom-Csv to use the list separator for the current culture as the delimiter.

    The objects that ConvertFrom-Csv creates are CSV versions of the original objects. The property values of the CSV objects are string versions of the property values of the original objects. The CSV versions of the objects do not have any methods.

    You can also use the Export-Csv and Import-Csv cmdlets to convert objects to CSV strings in a file (and back). These cmdlets are the same as the ConvertTo-Csv and ConvertFrom-Csv cmdlets, except that they save the CSV strings in a file.

PARAMETERS
    -Delimiter <char>
        Specifies the delimiter that separates the property values in the CSV strings. The default is a comma (,). Enter a character, such as a colon (:). To specify a semicolon (;), enclose it in quotation marks.

        If you specify a character other than the delimiter used in the CSV strings, ConvertFrom-Csv cannot create objects from the CSV strings. Instead, it returns the strings.

        Required?                    false
        Position?                    2
        Default value                ‘,’
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Header <string[]>
        Specifies an alternate column header row for the imported string. The column header determines the names of the properties of the object that ConvertFrom-Csv creates.

        Enter a comma-separated list of the column headers. Enclose each item in quotation marks (single or double). Do not enclose the header string in quotation marks. If you enter fewer column headers than there are columns, the remaining columns will have no headers. If you enter more headers than there are columns, the extra headers are ignored.

        When using the Header parameter, omit the column header string from the CSV strings. Otherwise, ConvertFrom-Csv creates an extra object from the items in the header row.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <PSObject[]>
        Specifies the CSV strings to be converted to objects. Enter a Variable that contains the CSV strings or type a command or expression that gets the CSV strings. You can also pipe the CSV strings to ConvertFrom-Csv.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByValue, ByPropertyName)
        Accept wildcard characters? false

    -UseCulture [<SwitchParameter>]
        Use the list separator for the current culture as the string delimiter. The default is a comma (,).

        To find the list separator for a culture, use the following command: (Get-Culture).TextInfo.ListSeparator. If you specify a character other than the delimiter used in the CSV strings, ConvertFrom-Csv cannot create objects from the CSV strings. Instead, it returns the strings.

        Required?                    true
        Position?                    named
        Default value                Comma
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String
        You can pipe CSV strings to ConvertFrom-Csv.

OUTPUTS
    System.Management.Automation.PSObject
        ConvertFrom-Csv returns the objects described by the properties in the CSV strings.

NOTES

        Because the imported objects are CSV versions of the object type, they are not recognized and formatted by the Windows PowerShell type formatting entries that format the non-CSV versions of the object type.

        In CSV format, each object is represented by a comma-separated list of the property values of the object. The property values are converted to strings (by using the ToString() method of the object), so they are generally represented by the name of the property value. ConvertTo-Csv does not export the methods of the object.

    ————————– EXAMPLE 1 ————————–

    C:\PS>$p = Get-Process | ConvertTo-Csv

    C:\PS> $p | ConvertFrom-Csv

    Description
    ———–
    These commands convert the processes on the local computer into CSV format and then restore them to object form.

    The first command uses the Get-Process cmdlet to get the processes on the local computer. A pipeline operator (|) sends them to the ConvertTo-Csv cmdlet, which converts the process object to CSV format. The CSV strings are saved in the $p Variable.

    The second command uses a pipeline operator to send the CSV strings in the $p Variable to the ConvertFrom-Csv cmdlet. The cmdlet converts the CSV strings into CSV versions of the original process objects.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$date = Get-Date | ConvertTo-Csv -Delimiter “;”

    C:\PS> ConvertFrom-Csv -InputObject $date -Delimiter “;”

    Description
    ———–
    These commands convert a data object to CSV format and then to CSV object format.

    The first command uses the Get-Date cmdlet to get the current date and time. A pipeline object (|) sends the date to the ConvertTo-Csv cmdlets, which converts the date object to a series of CSV strings. The command uses the Delimiter parameter to specify a semicolon delimiter. The strings are saved in the $date Variable.

    The second command uses the ConvertFrom-Csv cmdlet to convert the CSV strings in the $date Variable back to object format. The command uses the InputObject parameter to specify the CSV strings and the Delimiter parameter to specify the semicolon delimiter.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$j = Start-Job -scriptblock { Get-Process } | ConvertTo-Csv

    C:\PS> $header = “MoreData”,”StatusMessage”,”Location”,”Command”,”State”,”Finished”,”InstanceId”,”SessionId”,”Name”,”ChildJobs”,”Output”,”Error”,”Progress”,”Verbose”,”Debug”,”Warning”,”StateChanged”

    # Delete header from $j
    C:\PS> $j = $j[0], $j[2..($j.count – 1)]

    $j | ConvertFrom-Csv -Header $header

    MoreData     : True
    StatusMessage :
    Location     : localhost
    Command     : Get-Process
    State         : Running
    Finished     : System.Threading.ManualResetEvent
    InstanceId    : 6fcb6578-7f42-4d93-9f23-9937f6aac1a2
    SessionId     : 1
    Name         : Job1
    ChildJobs     : System.Collections.Generic.List`1[System.Management.Automation.Job]
    Output        : System.Management.Automation.PSDataCollection`1[System.Management.Automation.PSObject]
    Error         : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ErrorRecord]
    Progress     : System.Management.Automation.PSDataCollection`1[System.Management.Automation.ProgressRecord]
    Verbose     : System.Management.Automation.PSDataCollection`1[System.String]
    Debug         : System.Management.Automation.PSDataCollection`1[System.String]
    Warning     : System.Management.Automation.PSDataCollection`1[System.String]
    StateChanged :

    Description
    ———–
    This example shows how to use the Header parameter of ConvertFrom-Csv to change the names of properties in the resulting imported object.

    The first command uses the Start-Job cmdlet to start a background job that runs a Get-Process command on the local computer. A pipeline operator (|) sends the resulting job object to the ConvertTo-Csv cmdlet, which converts the job object to CSV format. An assignment operator (=) saves the resulting CSV in the $j Variable.

    The second command saves a header in the $header Variable. Unlike the default header, this header uses “MoreData” instead of “HasMoreData” and “State” instead of “JobStateInfo”.

    The third command deletes the original header (the second line) from the CSV strings and returns it to the $j Variable.

    The fourth command uses the ConvertFrom-Csv cmdlet to convert the CSV strings to a CSV version of the job object. The command uses a pipeline operator to send the content in $j to ConvertFrom-Csv. The resulting object has “MoreData” and “State” properties, as specified by the header.

    ————————– EXAMPLE 4 ————————–

    C:\PS>(Get-Culture).textinfo.listseparator

    C:\PS> ConvertFrom-Csv -InputObject $services -UseCulture

    Description
    ———–
    The command uses the ConvertFrom-Csv cmdlet to convert CSV strings of service objects that had been converted by the ConvertTo-Csv cmdlet. The command uses the UseCulture parameter to direct ConvertFrom-Csv to use the delimiter (list separator) of the current culture.

    When using the UseCulture parameter, be sure that the list separator of the current culture matches the delimiter used in the CSV strings. Otherwise, ConvertFrom-Csv cannot generate objects from the CSV strings.

    In this example, a Get-Culture command was used to verify the list separator, before the ConvertFrom-Csv command was used.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135201
    ConvertTo-Csv
    Export-Csv
    Import-Csv