逐行读取txt并查询AD [英] Read txt line by line and query AD
本文介绍了逐行读取txt并查询AD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 samids 的文本文件:
I have a text file containing samids:
XXXXXXX
YYYYYYY
ZZZZZZZ
对于每一个我都需要阅读它来查询广告:
For each one I need to read it quering AD with this:
dsquery user forestroot -samid XXXXXXX | dsget user -email
并将响应写入另一个文件.请帮助我:)
and write the response into another file. Please help me :)
推荐答案
使用 ActiveDirectory
PowerShell 模块中的 Get-ADUser
而不是 ds 工具:
Use Get-ADUser
from the ActiveDirectory
PowerShell module instead of the ds tools:
Import-Module ActiveDirectory
Get-Content 'C:path oinput.txt' |
Get-ADUser -SearchBase 'DC=example,DC=org' -Property mail |
select -Expand mail | Out-File 'C:path ooutput.txt'
其中 DC=example,DC=org
是您的林根域的专有名称 (DN).
Where DC=example,DC=org
is the distinguished name (DN) of your forest root domain.
要以编程方式确定林根域的 DN,您可以使用:
For programmatically determining the DN of the forest root domain you could use this:
([ADSI]"LDAP://RootDSE").RootDomainNamingContext
这篇关于逐行读取txt并查询AD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文