Good Morning,

Formatting a CSV, trying to trim a column for just the first character as follows:

Try{
$FileData | ForEach-Object{$_.MiddleName= $_.MiddleName.substring(0,1)}
}
Catch{}

$FileData being the import-csv with headers…

It appears that this code is working, until there’s a blank in that column, which then it stops processing that column. how do I get around this?

I’ve taken it out of the Try/Catch… which makes it work, but then I get an error everytime it doesn’t work… which I hate so much blood on my screen.

1 Spice up

or just put an if statement in it to see if it is null or not

1 Spice up

I had tried this before, but I guess it had a typo somewhere, as now it’s working… I think I was using

If($_.MiddleName -ne ''){...}

as opposed to:

If($_.MiddleName){...}

The bottom option is working…