【发布时间】:2014-03-17 09:36:13
【问题描述】:
我有一个包含 samids 的文本文件:
XXXXXXX
YYYYYYY
ZZZZZZZ
对于每一个我都需要阅读它来查询广告:
dsquery user forestroot -samid XXXXXXX | dsget user -email
并将响应写入另一个文件。请帮帮我:)
【问题讨论】:
标签: powershell active-directory
我有一个包含 samids 的文本文件:
XXXXXXX
YYYYYYY
ZZZZZZZ
对于每一个我都需要阅读它来查询广告:
dsquery user forestroot -samid XXXXXXX | dsget user -email
并将响应写入另一个文件。请帮帮我:)
【问题讨论】:
标签: powershell active-directory
使用ActiveDirectory PowerShell 模块中的Get-ADUser 而不是 ds 工具:
Import-Module ActiveDirectory
Get-Content 'C:\path\to\input.txt' |
Get-ADUser -SearchBase 'DC=example,DC=org' -Property mail |
select -Expand mail | Out-File 'C:\path\to\output.txt'
其中DC=example,DC=org 是林根域的专有名称 (DN)。
要以编程方式确定林根域的 DN,您可以使用以下命令:
([ADSI]"LDAP://RootDSE").RootDomainNamingContext
【讨论】:
最后,我设法解决了另一个帖子中提出的这种方式:
$a = Get-Content .\input.txt
for ($i=0 ; $i -lt $a.Length; $i++){
dsquery user forestroot -samid $a[$i] | dsget user -email | Select-String '@' | select -Expand Line >> output.txt
}
谢谢
【讨论】: