MDM*_*rra 3 windows powershell active-directory
我正在尝试枚举林中每个用户所属的名称、samaccountname 和域,并将其写入文本文件。
我现在拥有的脚本是:
Import-Module ActiveDirectory
$domains = "root.org", "child1.root.org", "child2.root.org"
ForEach ($d in $domains){
Get-ADUser -Filter * -ResultSetSize $null -Server $d -Properties name, samaccountname |
Select-Object name, samaccountname | out-file c:\users\mdmarra\desktop\users.txt -append
}
Run Code Online (Sandbox Code Playgroud)
我需要的是每行末尾的 $d 值,以便输出看起来像
name samaccountname domain
---- -------------- ------
Marra,Mark mdmarra root.org
Run Code Online (Sandbox Code Playgroud)
这是您可以使用哈希表轻松实现的事情Select-Object:
ForEach ($d in $domains){
Get-ADUser -Filter * -ResultSetSize $null -Server $d -Properties name, samaccountname |
Select-Object name, samaccountname, @{ Name = 'domain'; Expression = { $d }} | out-file c:\users\mdmarra\desktop\users.txt -append
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
483 次 |
| 最近记录: |