I
I
Igor_Andersen2016-08-24 11:52:51
PowerShell
Igor_Andersen, 2016-08-24 11:52:51

How to replace a character inside all array elements after import-csv?

There is a part in the crypt where a variable with csv is created:

$header = "property1","property2"
$dt = Import-Csv $tempfile  -delimiter "," -header $header

You must then remove the sign ' in all elements.
I understand how to make a replacement by explicitly specifying each property,
$dt | % {
    $_.'property1' = $_.'property1'.replace("'","")
    $_.'property2' = $_.'property2'.replace("'","")
    }

but how to do it in one line without explicitly specifying ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly, 2016-10-14
@rbobot

Do a Get-Content import, remove all characters, then send it to ConvertFrom-CSV.

A
Andrew AT, 2017-01-07
@AAT666

$dt | %{foreach($h in $header){$_.$h = $_.$h.replace("'","")} }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question