0

如何生成自特定日期以来已更新的 AD 中所有用户帐户的列表(可能是电子表格)?

我正在考虑在 C# 中执行此操作,但任何 .net 方法都是可以接受的。

这里是上下文:我在我的共享点门户中使用了一个组件,它允许用户自己更新他们的 AD 配置文件。但是,我还需要更新我的邮件列表,因此我需要知道他们何时更新他们的电子邮件地址。因此,我需要获取更改。

4

1 回答 1

1

AD 在高级查询方面很慢。我想从 AD 中提取完整的用户列表然后搜索邮件列表中的更改可能会更便宜,假设您将它们放在数据库中。用户名及其电子邮件的完整列表应该会很快生成(当然取决于用户数量)。

编辑:一个简单的辅助 Powershell 脚本,用于快速从 AD 中获取用户

# Get the RootDSE
$rootDSE=[ADSI]"LDAP://RootDSE"

# Get the defaultNamingContext
$Ldap="LDAP://"+$rootDSE.defaultNamingContext

# Create the output file
$outFile=".\users\userList_{0:yyyyMMdd-HHmm}.csv" -f (Get-Date)

# Get all users 
$filter="(&(ObjectClass=user))"

# create the Header for the Output File
$header="name;userPrincipalName;mail"
$timeStamp=

# Check if the file exists and if it does with the same timestamp remove it
if(Test-Path $outFile)
{
  Remove-Item $outFile
}

# create the output file and write the header
Out-File -InputObject $header -FilePath $outFile

# main routine
function GetUserListToFile()
{
  # create a adsisearcher with the filter
  $searcher=[adsisearcher]$Filter

  # setup the searcher properties
  $Ldap = $Ldap.replace("LDAP://","")
  $searcher.SearchRoot="LDAP://$Ldap"
  $searcher.propertiesToLoad.Add("name")
  $searcher.propertiesToLoad.Add("userPrincipalName")
  $searcher.propertiesToLoad.Add("mail")

  $searcher.pageSize=1000

  # find all objects matching the filter
  $results=$searcher.FindAll()

  # create an empty array
  $ADObjects = @()
  foreach($result in $results)
  {
    # work through the array and build a custom PS Object
    [Array]$propertiesList = $result.Properties.PropertyNames
    $obj = New-Object PSObject
    foreach(property in $propertiesList)
    { 
       $obj | add-member -membertype noteproperty -name $property -value ([string]$result.Properties.Item($property))
    }
    # add the object to the array
    $ADObjects += $obj

    # build the output line
    $lineOut=$obj.Name+";"+ $obj.UserPrincipalName+";"+ $obj.mail

    # Write the line to the output file
    Out-File -Append -InputObject $lineOut -FilePath $outFile
  }

  Return $ADObjects
}

# main routine
GetUserListToFile
于 2013-10-15T18:37:40.513 回答