有人可以通过比较AD用户中的2个属性给我一些建议吗?我想扫描OU中的用户帐户,并比较2个属性以查看它们是否匹配。
我从以下表达式开始,查看所有细节:
Uncaught TypeError: window.Group is not a constructor(…)
我需要比较办公室和城市,并导出与csv不匹配的结果帐户。
我是否必须导入列表,还是可以使用get-ADUser表达式的结果?
答案 0 :(得分:0)
两个简单的循环(假设名称是唯一的)如下:
$file = Import-CSV C:\example.csv
$Users = get-ADUser -searchbase "OU=users,OU=company,DC=blah,DC=blah,DC=com" -filter * -properties name, physicaldeliveryofficename | Select name, physicaldeliveryofficename
foreach ($user in $users) {
foreach {$entry in $file) {
if ($user.name -eq $entry.name) {
if ($user.physicaldeliveryofficename -eq $entry.physicaldeliveryofficename) {
#Both match
} else {
#Does not match
}
}
}
}
答案 1 :(得分:0)
结束了这一点,效果很好。
## Returns all AD users where the city attribute and Office attribute don't match
#Creates an array for output
$Outarray = @()
$Users = get-ADUser -searchbase "OU=blah,OU=blah,DC=blah,DC=blah,DC=blah" - filter * -properties * | Select samaccountname, name, l, physicaldeliveryofficename
#Writes name, username, office and city to the array where city and office don't match
foreach ($user in $users) {
if ($user.physicaldeliveryofficename -eq $user.l) {
#They Match
} else {
$outarray += $user.name + ","+ $user.samaccountname + "," + $user.physicaldeliveryofficename + "," + $user.l
}
}
#creates a CSV file, delimited with a comma
#change path to your location
$outarray |sort-object| out-file "c:\temp\output.csv"
答案 2 :(得分:0)
根据相关两个属性的不等式过滤用户对象,然后将它们导出为CSV:
$ou = 'OU=users,OU=company,DC=example,DC=com'
Get-ADUser -SearchBase $ou -Filter * -Properties * |
Where-Object { $_.l -ne $_.physicaldeliveryofficename } |
Select-Object SamAccountName, Name, l, physicaldeliveryofficename |
Export-Csv 'C:\path\to\output.csv' -NoType