1

I would like to know why when I run my script the result shows me ";" between my arrays. I'm actually trying to compare two excel columns and display the difference. If a cell isn't in the first column but is in the second it display the column. How can I remove these ";" and get the difference between the columns? I've also tried with some files with one column and it works

result:

ComputerName;;;;;OtherComputerName
----------------------------------
uiojk;;;;;uih                     
hjbyu;;;;;ubyhi`

script:

#get the content of the column in the file
[string[]]$a = import-csv '.\test1.csv' | select -expand ComputerName
[string[]]$d = import-csv '.\test1.csv' | select -expand OtherComputerName

#display the cells which aren't in the $a list

$d |? {$a -notcontains $_}

#displays the columns of one file

[Array]$stores[2].ComputerName
[Array]$stores[2].OtherComputerName

$stores 

1 Answer 1

2

Import-Csv uses a comma as the default delimiter, if you want to use another character then you will need to use the -Delimiter option. Something like this:

$x = Import-Csv .\test1.csv -Delimiter ';'
Compare-Object -ReferenceObject $x.ComputerName -DifferenceObject $x.OtherComputerName

This code will generate a warning because not all your CSV columns have an header, but it will still work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.