比较两个.CSV文件并输出重复的名称 [英] Compare two .CSV files and output the duplicate names

查看:272
本文介绍了比较两个.CSV文件并输出重复的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Powershell的新手,标题几乎指出了我正在尝试做的事情.我这里有两个.CSV文件,其中包含一个组的用户名,另一个包含一个OU.我需要比较该组和OU的用户列表,然后继续从AD中的该组删除重复项.

I'm new to Powershell, and the title pretty much points out what I'm trying to do. I have here two .CSV files that includes the usernames of a group and the other an OU. I need to compare the userlist of the group and the OU then proceed with deleting the duplicates from the group in AD.

我一直在四处搜寻,并找到了一些线索,但是作为新的Powersheller,我无法将发现的内容结合到可以执行我想要的工作的命令中.

I've been googling around, and have found a few leads, but me being a new Powersheller I have not been able to combine what I've found into a working command that does what I want it to.

这是我要比较的.CSV文件的格式. Samaccountname(标题)不应进行比较.

Here is the format of the .CSV files that I want to be compared. Samaccountname (the header) should not be compared.


"samaccountname"
"tb2"
"tb3"
"tb4"

推荐答案

$Group = import-csv -path C:\Output\Test.csv
$OU = import-csv -path C:\Output\DomainUsers.csv
Compare-Object $Group $OU -property samaccountname -IncludeEqual | where-object {$_.SideIndicator -eq "=="} | Export-csv C:\Output\Difference.csv –NoTypeInformation

是我一直在寻找的代码.

is the code I was looking for.

这篇关于比较两个.CSV文件并输出重复的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆