在我的问题之后:
我有一个csv文件,如下所示:
#TYPE System.Management.Automation.PSCustomObject
"Enrolled User";"Device ID"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"16"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"18"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"20"
"xmipadusa@arnaud.biz ""XenMobile Shared iPad Enrolment User""";"22"
"xmtest02@arnaud.biz ""xmtest02""";"26"
"xmtest01@arnaud.biz ""xmtest01""";"46"
"xmipaden@arnaud.biz ""XenMobile Shared iPad Enrolment User""";"61"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"62"
"martind@arnaud.biz ""Martin Dupont - Head of IT Service Delivery""";"66"
"xmtest01@arnaud.biz ""xmtest01""";"70"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"75"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"76"
"xmipodusa@arnaud.biz ""XenMobile Shared iPod Enrolment User""";"80"
"xmtest01@arnaud.biz ""xmtest01""";"81"
"xmtest01@arnaud.biz ""xmtest01""";"83"
"xmipaden@arnaud.biz ""XenMobile Shared iPad Enrolment User""";"88"
"rogerd@arnaud.biz ""Roger Durand - Head of HR""";"89"
我想创建一个脚本来删除唯一值,并且只保留csv文件中多次出现的值(基于第1列,#34;注册用户")。
感谢您提供任何意见/帮助。
干杯, 阿诺
答案 0 :(得分:3)
我会使用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 ';'
另请注意,您可以在导出CSV时删除#TYPE System.Management.Automation.PSCustomObject
内容,方法是在-NoTypeInformation
上指定Export-Csv
参数。