Cleanup CSV by values similar values and keep one special


I created a script that reads out the ADgroups that have accessrights to networkshares, as listed in a txt file, and that reads out all ADUsers that are in those groups and saves them in a csv including which rights they have

My Prob: there are several People in multible Groups at some shares, so they appear multible times in the csv.

My question:
How do I delete double entriys in a csv by one column and leave the one with one special value in one of the columns?

Example: I got a csv with


I want to end up with:


Welcome to the forum. :wave:t4:

This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

What exactly does that mean? Processing your example from the top to the bottom I’d expect the data set Max;123456;ReadOnly to survive - not the one with the Write.

When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.



what’s wrong? Why do you ask your question again on StackOverflow before you even answer the back question you get here?

Hi Olaf
I guessed by get-Content select-object -unique, but that does not solve my problem that I want to keep the one with a specified value in the 3rd column.
I actually have no clue at all how I should get there

And you don’t read and answer my question.

WHAT specified value???

Why should I only ask the question in one forum?
The probability of getting an answer is increased by asking the question in several forums.

Because that would be considered good manner. Because in case it would decrease the effort people willing to help you have to spend.

And I actually did not say you should no post in other forums - I said you should let the people know that you already asked somewhere else.

Could you please answer my question?

What specified value?

In my case I want do search the csv for duplicate employeenumbers, delete the duplicates and keep only the one with the value “write” in Accessrights

'@ |
    ConvertFrom-Csv -Delimiter ';' |
        Sort-Object -Property Name, Accessrights -Descending |
            Group-Object -Property Name |
                ForEach-Object {
1 Like

Wow thanks
And no offense, I’m a PS novice, I hardly stay in forums on such topics, but look for my answers piece by piece, I didn’t know that this would be interpreted so negatively.
Thank you for your help :slight_smile:

Wouldn’t it be expected to behave in a good manner in Austria when you freshly come to a new group of people you don’t know and you expect help from?

So it is in communities in the internet as well. And I asked what value you want to keep in my first reply 2 hours ago. :wink:

1 Like

Thanks again for the help :slight_smile:
Yes, I actually missed the part where you ask me about the value, sorry for that again.
The method is thought outside the box, I focused all the time on first bringing the duplicate employee numbers together and then deleting the entry according to the value in the permissions instead of sorting by permission.
Learned something new again :slight_smile: