How to change each column and row from a CSV file to upper case?

34 Views Asked by At

existing code:

$in = Import-Csv .\in.csv
$TextInfo = (New-Object System.Globalization.CultureInfo("en-US")).TextInfo;
$in | ForEach-Object { $_.name = $textInfo.ToUpper($_.name) }
$in | Export-Csv .\out.csv

This will convert the case ToUpper or can be ToTitleCase optionally.

How would each column be iterated?

Tried to get the column names as below. Just need to better understand how to iterate each column rather than a specific named column. How is the count of CSV columns determined? How is each column referenced in a loop as above?

Ideally, using the REPL console as below.

PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $in = Import-Csv .\in.csv
PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $TextInfo = (New-Object System.Globalization.CultureInfo("en-US")).TextInfo;
PS C:\Users\Nick\Desktop> $in.PSObject.Properties.Name
Count
Length
LongLength
Rank
SyncRoot
IsReadOnly
IsFixedSize
IsSynchronized
PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $in | Format-Table

alpha      beta       charlie    delta
-----      ----       -------    -----
sdkljgsdf  bdgfhgfnhm ngfgfddfsg dfhgsdfg
gfjdsaklbf dfbdfgfn   vfsdafdfbn fgjtyj
bdgfkl     dsfsd      vgngfas    dsfhgtj
dsbmnkl    nggfn      bfdsda     edtshdgf
asdfkl     sdagfdfh   vbdfdngt   ngfggj


PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $in.PSObject.Properties[2].Value
PS C:\Users\Nick\Desktop>

Also:

PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop>
PS C:\Users\Nick\Desktop> $in | Get-Member -MemberType Properties


   TypeName: System.Management.Automation.PSCustomObject

Name    MemberType   Definition
----    ----------   ----------
alpha   NoteProperty string alpha=sdkljgsdf
beta    NoteProperty string beta=bdgfhgfnhm
charlie NoteProperty string charlie=ngfgfddfsg
delta   NoteProperty string delta=dfhgsdfg


PS C:\Users\Nick\Desktop>

will get the column names: alpha, beta, etc. But how would each be passed and iterated to change the case of all "cells" as above?

see also:

PowerShell - Import-Csv - referencing a column by its position

How to convert a specific CSV column to TitleCase with PowerShell from the REPL console?

https://stackoverflow.com/a/34131869/22063140

0

There are 0 best solutions below