Export PowerCLI results to CSV
How exporting PowerCLI output to CSV or TSV works, what it changes about your vSphere data, and when another format or plain text serves you better.
Exporting PowerCLI results to CSV is one of the most common ways to turn vSphere inventory data into something a spreadsheet, a ticketing system or a colleague can use. The export is simple to start, but it is a real transformation. Rich PowerShell objects become flat rows of text, and some meaning can be lost along the way. This review explains what the conversion changes, where it works well, and when a different format or plain text is the better choice.
Is CSV export the right fit for your use?
CSV works well when your data is a flat list with one record per object and a fixed set of simple properties. A VM inventory with names, power states, CPU counts and memory sizes is a good example. The main benefit is reach: almost every spreadsheet, database import tool and scripting language can read comma- or tab-separated text.
The main tradeoff is that CSV holds only text in rows and columns. Data types, nested objects and multi-valued properties do not survive unless you flatten them yourself before exporting. If you skip that step, the file can look complete while columns contain type names instead of values.
- CSV or TSV suits: inventory reports, audit snapshots, spreadsheet analysis, and bulk imports into other systems.
- JSON (ConvertTo-Json) suits: data with nested structure that another program will read.
- CLIXML (Export-Clixml) suits: data you plan to re-import into PowerShell with object types preserved as far as the format allows.
- Plain text (for example, Format-Table output saved with Out-File) suits: a quick human-readable summary pasted into a chat, email or ticket, where nobody will sort, filter or re-import the data.
What the export actually changes
PowerCLI cmdlets such as Get-VM return .NET objects, not text. Export-Csv is a standard PowerShell cmdlet, not a PowerCLI-specific one. It takes those objects and writes one row per object and one column per property. Each value is converted to a string. That conversion causes most of the surprises.
- Columns come from the first object. Export-Csv builds the header from the properties of the first object it receives. Properties that appear only on later objects are dropped.
- Nested and collection values are stringified. A property holding an array or a complex object may appear as a type name such as System.Object[] rather than its contents.
- Types are lost. Numbers, dates and Booleans become text. Reading the file back with Import-Csv returns strings for every value.
- A type header may be added. Windows PowerShell 5.1 writes a #TYPE line at the top of the file unless you pass -NoTypeInformation. PowerShell 7 omits it by default.
- Formatting output is not data. Piping Format-Table or Format-List into Export-Csv writes formatting instructions instead of your values. Use Select-Object to shape the data, and use the Format cmdlets only for screen display.
The reliable pattern is to choose and flatten properties explicitly with Select-Object, then export. Calculated properties let you turn related or multi-valued data into a single string.
Get-VM |
Select-Object Name, PowerState, NumCpu, MemoryGB,
@{Name='Host'; Expression={ $_.VMHost.Name }},
@{Name='Datastores'; Expression={ (Get-Datastore -RelatedObject $_).Name -join ';' }},
@{Name='GuestOS'; Expression={ $_.Guest.OSFullName }},
@{Name='IPs'; Expression={ $_.Guest.IPAddress -join ';' }} |
Export-Csv -Path .\vm-inventory.csv -NoTypeInformation -Encoding UTF8
This example assumes an active Connect-VIServer session. Joining arrays with a semicolon keeps multi-valued fields inside one comma-delimited column. It also makes clear to readers that the field holds several values. Guest properties such as the OS name and IP addresses depend on VMware Tools reporting them, so expect blanks for some VMs. No output from this command was captured for this article. Check the result against your own environment before relying on it.
CSV versus TSV and other delimiters
Export-Csv uses a comma by default. The -Delimiter parameter changes it. A tab produces TSV, which can be easier to paste into some spreadsheets and is less likely to clash with commas inside values. The -UseCulture parameter uses the list separator of the current regional settings. That can help in locales where spreadsheets expect a semicolon, but the same file may then behave differently on a machine with other settings.
Get-VM | Select-Object Name, PowerState, NumCpu |
Export-Csv -Path .\vms.tsv -Delimiter "`t" -NoTypeInformation
| Option | Effect | When to use it |
| -NoTypeInformation | Omits the #TYPE header line | Always in Windows PowerShell 5.1 unless you need the header; already the default in PowerShell 7 |
| -Delimiter "`t" | Writes tab-separated output | Values often contain commas, or the target expects TSV |
| -UseCulture | Uses the regional list separator | The file stays within one regional setup |
| -Encoding | Sets the text encoding | Always state it explicitly when files move between systems |
| -Append | Adds rows to an existing file | Collecting results over several runs with identical columns |
| ConvertTo-Csv | Returns CSV lines instead of writing a file | Passing CSV to another command or API in memory |
Will the file stay readable after you share it?
CSV is plain text, so copying and pasting it does not change the stored characters. Readability problems usually appear when another program interprets the file. They come from three main sources: encoding, delimiters and spreadsheet auto-conversion.
- Encoding: Default encodings differ between Windows PowerShell 5.1 and PowerShell 7. Names containing accented or non-Latin characters can be garbled if the reader assumes a different encoding. Set -Encoding explicitly. Whether a spreadsheet detects UTF-8 correctly can depend on the presence of a byte order mark and on the application version, so test with the program your recipients use.
- Delimiters: A comma-delimited file opened where the regional list separator is a semicolon may load as a single column. Agree on the delimiter with the recipient, or use TSV.
- Auto-conversion: Spreadsheets may reformat values that look like numbers or dates. For example, they may drop leading zeros or reinterpret decimal sizes under a different locale. The stored file is unchanged, but what the recipient sees differs.
- Formula injection: Values beginning with characters such as =, +, - or @ can be treated as formulas when opened in a spreadsheet. VM names, notes and custom attributes may be set by many people, so treat exported text as untrusted when sharing it widely.
For accessibility, a CSV opened in a spreadsheet with a clear header row is generally easier for screen-reader users to navigate than a screenshot or column-aligned text that relies on spacing. No assistive-technology testing was done for this article. If accessibility matters for your audience, check the file with the tools they use. When the recipient only needs to read a few values, a short plain-text summary may be more usable than an attached file.
Round-tripping the data
If you plan to read the export back into PowerShell, remember that Import-Csv returns every field as a string. Comparisons and sorting on numeric columns need an explicit cast, such as [int]$_.NumCpu, or the results will follow text order. Joined fields need to be split again. If a later PowerShell script is the only consumer, Export-Clixml avoids most of this work, though the file is much less convenient for people to read.
Gaps in this review
No measurements, version-specific test results or vendor documentation excerpts were available for this review. The behaviors described are general characteristics of PowerShell's CSV cmdlets and common spreadsheet handling. Exact defaults, available parameters and spreadsheet import behavior vary by PowerShell version, PowerCLI version, operating system and regional settings. Confirm them in your own environment before standardizing on a workflow.
Bottom line
Exporting PowerCLI results to CSV is a sound choice for flat, tabular inventory data that people will sort, filter or import elsewhere. It preserves meaning only when you select and flatten properties yourself, avoid Format cmdlets in the pipeline, and set the encoding and delimiter deliberately. Choose JSON or CLIXML when structure or types matter, and plain text when the output is just a quick summary for a person to read.