0

Here after my problem:

I have a csv file which look like:

#TYPE System.Management.Automation.PSCustomObject
"Enrolled User";"Device ID"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"16"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"18"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"20"
"[email protected] ""XenMobile Shared iPad Enrolment User""";"22"
"[email protected] ""xmtest02""";"26"
"[email protected] ""xmtest01""";"46"
"[email protected] ""XenMobile Shared iPad Enrolment User""";"61"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"62"
"[email protected] ""Martin Dupont - Head of IT Service Delivery""";"66"
"[email protected] ""xmtest01""";"70"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"75"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"76"
"[email protected] ""XenMobile Shared iPod Enrolment User""";"80"
"[email protected] ""xmtest01""";"81"
"[email protected] ""xmtest01""";"83"
"[email protected] ""XenMobile Shared iPad Enrolment User""";"88"
"[email protected] ""Roger Durand - Head of HR""";"89"

I would like to create a script to remove the unique value and keep only the values that are present more than once (based on 1st column, "Enrolled User")in the csv file.

Thanks for any input/help.

Cheers, Arnaud

1 Answer 1

3

I would use the Group-Object cmdlet

Import-Csv -Path $FileName -Delimiter ';' |
    Group-Object -Property "Enrolled User" |
    Where-Object Count -gt 1 |
    Select-Object -ExpandProperty Group |
    Export-Csv -Path $NewFileName -Delimiter ';'

Also, note that you can remove the #TYPE System.Management.Automation.PSCustomObject stuff when exporting a CSV by specifying the -NoTypeInformation parameter on Export-Csv.

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

1 Comment

Thanks for the quick answer, it works like a charm ;)

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.