The property of invoking an EE object for a csv file changes without spaces to have spaces

Due to a recent change, this is pretty much a continuation of this - Remove leading zeros in the csv file only from int values

I have the following code:

Import-CSV "C:\path\test.csv" | ForEach-Object{
    $_.column1 = ($_.column1).TrimStart('0')
    $_
} | Export-Csv "C:\path\test2.csv" -NoTypeInformation
Move-Item "C:\path\test2.csv" "C:\path\test.csv" -Force

After reading the following code:

Import-CSV "C:\path\test.csv" | ForEach-Object{
    $_.column 1 = ($_.column 1).TrimStart('0')
    $_
} | Export-Csv "C:\path\test2.csv" -NoTypeInformation
Move-Item "C:\path\test2.csv" "C:\path\test.csv" -Force

Now in the csv file has column1been changed to column 1(now there is a space).

I get a syntax compilation error:

Unexpected token 'One' in expression or statement.
At :line:2 char:19
+       $_.Column One  <<<< = ($_.Column One).TrimStart('0')

Any help with this would be much appreciated ...

+4
source share
1 answer

The answer was found on this site: http://itknowledgeexchange.techtarget.com/powershell/csv-fields-with-spaces-in-the-field-name/

Import-CSV "C:\path\test.csv" | ForEach-Object{
    $_.'column 1' = ($_.'column 1').TrimStart('0')
    $_
} | Export-Csv "C:\path\test2.csv" -NoTypeInformation
Move-Item "C:\path\test2.csv" "C:\path\test.csv" -Force
0
source

Source: https://habr.com/ru/post/1620170/


All Articles