How to Export and import CSV file manually in PowerShell?


When you run a command Export-Csv in PowerShell, it automatically creates a CSV file to the specific location.

Example

Get-Service | Select Name, Starttype, Status | Export-Csv C:\temp\services.csv -NoTypeInformation

In the above example, Services.csv file created in C:\Temp folders with the header Name, Starttype, and Status headers.

Similarly, you can use the other commands to get the output into the CSV file format.

If you want to check this file from the PowerShell console, you need to use Import-CSV command.

Import-Csv C:\temp\Services.csv | ft -Autosize

Output

Name                                     StartType       Status
----                                     ---------       ------
AarSvc_7a82a                             Manual          Stopped
AdobeARMservice                          Automatic       Running
AdobeFlashPlayerUpdateSvc                Manual          Stopped
AJRouter                                 Manual          Stopped
ALG                                      Manual          Stopped
AppIDSvc                                 Manual          Stopped
Appinfo                                  Manual          Running
AppMgmt                                  Manual          Stopped
AppReadiness                             Manual          Stopped
AppVClient                               Disabled        Stopped
AppXSvc                                  Manual          Stopped
AssignedAccessManagerSvc                 Manual          Stopped
AudioEndpointBuilder                    Automatic        Running

If you need only Name and Status then you can use Select command after pipeline

Import-Csv C:\temp\Services.csv | Select Name,Status

Output

Name                                        Status
----                                        ------
AarSvc_7a82a                                Stopped
AdobeARMservice                             Running
AdobeFlashPlayerUpdateSvc                   Stopped
AJRouter                                    Stopped
ALG                                         Stopped
AppIDSvc                                    Stopped
Appinfo                                     Running
AppMgmt                                     Stopped
AppReadiness                                Stopped
AppVClient                                  Stopped
AppXSvc                                     Stopped

Updated on: 26-Mar-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements