我前几天发布了这个问题从分组对象中提取电子邮件 https://stackoverflow.com/questions/30856287/extract-e-mail-from-grouped-objects/30856711?noredirect=1#comment49758538_30856711
$OuUser = @{}
$OuUser = Get-AdUser -Properties * -Filter * -SearchBase "domain"
$Duplicates = $OuUser | Select samaccountname, mail,UserPrincipalName |
Group-Object Mail | Where{$_.Count -gt 1}
$Duplicates | Select Name,Count,@{l='Accounts';e={($_.Group|Select -Expand samaccountname) -join ';'}} |
Export-CSV E:\Damo\Duplicates.csv -NoTypeInfo
该代码在一个域上运行良好,针对 OU 中的一小组用户进行测试。
在我想要测试的域上进行测试时,该域中有很多用户,此代码失败。 OU 中包含非电子邮件格式的电子邮件地址。它指向 Get-ADUser 的错误。
Get-ADUser : The server has returned the following error: invalid enumeration c
ontext.
At C:\scripts\CountEmailsDup.ps1:4 char:21
+ $OuUser = Get-AdUser <<<< -Properties * -Filter * -SearchBase 'ou=external,o
u=user accounts,dc=bizdir,dc=nzpost,dc=co,dc=nz' -SearchScope OneLevel
+ CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException
+ FullyQualifiedErrorId : The server has returned the following error: inv
alid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.Ge
tADUser
我不明白为什么我在一个域上遇到此错误,但在另一个域上却没有。