Good Morning,<\/p>\n
Formatting a CSV, trying to trim a column for just the first character as follows:<\/p>\n
Try{\n$FileData | ForEach-Object{$_.MiddleName= $_.MiddleName.substring(0,1)}\n}\nCatch{}\n<\/code><\/pre>\n
Advertisement
$FileData being the import-csv with headers…<\/p>\n
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?<\/p>\n
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.<\/p>","upvoteCount":1,"answerCount":3,"datePublished":"2018-01-17T16:00:03.000Z","author":{"@type":"Person","name":"ryanstanford2","url":"https://community.spiceworks.com/u/ryanstanford2"},"acceptedAnswer":{"@type":"Answer","text":"
or just put an if statement in it to see if it is null or not<\/p>","upvoteCount":1,"datePublished":"2018-01-17T16:24:25.000Z","url":"https://community.spiceworks.com/t/csv-column-foreach-object-substring-works-until-it-doesnt/629215/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"
Good Morning,<\/p>\n
Formatting a CSV, trying to trim a column for just the first character as follows:<\/p>\n
Try{\n$FileData | ForEach-Object{$_.MiddleName= $_.MiddleName.substring(0,1)}\n}\nCatch{}\n<\/code><\/pre>\n$FileData being the import-csv with headers…<\/p>\n
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?<\/p>\n
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.<\/p>","upvoteCount":1,"datePublished":"2018-01-17T16:00:03.000Z","url":"https://community.spiceworks.com/t/csv-column-foreach-object-substring-works-until-it-doesnt/629215/1","author":{"@type":"Person","name":"ryanstanford2","url":"https://community.spiceworks.com/u/ryanstanford2"}},{"@type":"Answer","text":"