加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 使用Get-ADUser时,如何在PowerShell中将用户的域信息

发布时间:2020-12-13 22:51:17 所属栏目:Windows 来源:网络整理
导读:我正在尝试枚举林中每个用户所属的名称,samaccountname和域,并将其写入文本文件. 我现在的脚本是: Import-Module ActiveDirectory$domains = "root.org","child1.root.org","child2.root.org"ForEach ($d in $domains){Get-ADUser -Filter * -ResultSetSize
我正在尝试枚举林中每个用户所属的名称,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:usersmdmarradesktopusers.txt -append

}

我需要的是每行末尾的$d的值,以便输出看起来像

name          samaccountname        domain
----          --------------        ------
Marra,Mark    mdmarra               root.org
这是您可以使用Select-Object中的哈希表轻松实现的:
ForEach ($d in $domains){

Get-ADUser -Filter * -ResultSetSize $null -Server $d -Properties name,samaccountname,@{ Name = 'domain'; Expression = { $d }} | out-file c:usersmdmarradesktopusers.txt -append

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读