Use this when PowerShell reads or writes CSV.
CSV · PowerShell Automation
PowerShell handles CSV with Import-Csv, which turns rows into objects with properties from the header, and Export-Csv -NoTypeInformation for reports.
1. Import-Csv returns objects per row.
2. Specify delimiter and encoding.
3. Validate columns and values.
4. Export-Csv -NoTypeInformation.
5. Excel locale quirks (semicolon).
CSV → Import-Csv → objects → validation
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
Export a small fixture containing delimiters, quotes, empty values and non-ASCII text, then import it and compare required field names/counts and converted values. Check the raw header line when interoperability matters. For large data, validate row counts and rejected records rather than trusting only command completion.
Step 2 Common mistakes Narrow the fault
- Encoding problems with
Export-Csv(set-Encoding utf8).
Step 3 Where it fails Narrow the fault
CSV is a lossy serialization boundary for rich PowerShell objects. Export success does not show the receiving system parsed every row or preserved types. Keep object projection, text serialization, transport/storage and downstream import validation as separate steps.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Import-Csv returns objects with header names as properties.
- Export-Csv -NoTypeInformation writes clean files.
- Set -Delimiter and -Encoding explicitly.
Import-Csv f.csv -Delimiter ';'— importExport-Csv out.csv -NoTypeInformation -Encoding utf8— export- Required columns validation — input checks
ReferenceWhy it matters1 section · depth on demand
Worked example
Import-Csv and Export-Csv turn CSV files into objects and back, which makes bulk operations — creating users, updating devices, generating reports — straightforward.
Worked example: bulk-create AD users from HR data, validating each row and reporting results.
$results = Import-Csv .\new-users.csv -Delimiter ';' | ForEach-Object {
try {
if ($_.SamAccountName -notmatch '^[a-z]{3,20}$') { throw "invalid username" }
New-ADUser -Name $_.Name -SamAccountName $_.SamAccountName -Path $_.OU -Enabled $false -ErrorAction Stop
[pscustomobject]@{ User = $_.SamAccountName; Result = 'Created' }
} catch {
[pscustomobject]@{ User = $_.SamAccountName; Result = "Failed: $($_.Exception.Message)" }
}
}
$results | Export-Csv .\new-users-result.csv -NoTypeInformation -Encoding utf8
All imported values are strings — convert numbers and dates explicitly — and match the delimiter and encoding of files produced by Excel in your locale.
ReferenceImportant terms & boundaries1 section · depth on demand
PowerShell mechanics
Import-Csv maps header fields to object properties and Export-Csv serializes object property values into delimited text. CSV has no native PowerShell type/method metadata, so imported fields are generally textual representations that require deliberate conversion. Export property shape is driven by the objects presented to the cmdlet; formatting objects from Format-* are not the original data contract.
ReferenceConfiguration & state1 section · depth on demand
Authoring and lifecycle
Define headers, delimiter/culture, encoding and quoting expectations for the consumer. Project a stable property set before export and convert typed values explicitly on import when arithmetic/date/boolean semantics matter. Never pipe Format-Table or other formatting commands into Export-Csv; formatting belongs only at the final human-display boundary.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-7.5 · confidence 94%Quick lookup tables
CSV · PowerShell operational reference
Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.
| Boundary | CSV reference |
|---|---|
| Runtime identity | PowerShell edition/version + command/module source |
| Persistent intent | Script/module/config prerequisites under source control |
| Verification | Read-only discovery → execution evidence → independent target read-back |
| Output contract | Structured objects/streams before formatting |
| Failure boundary | Separate engine/binding from transport/API/native and target-state failures |
Deep reference
Healthy vs suspicious evidence
Output interpretation
A CSV that opens nicely in a spreadsheet can still violate the expected delimiter, encoding or schema. Imported numbers/dates may be strings until converted, and locale-specific formatting can silently change interpretation. Screen tables are not evidence of the raw CSV contract.