powershell - 从域本地组中导出用户
问题描述
你能帮我下面的代码吗?
它工作得很好,但我需要samAccountName
not thedistinguishedName
并且仅通过distinguishedName
替换samAccountName
.
这里是:
$s = "LDAP://" + (Get-ADGroup "Name of Group").DistinguishedName
([ADSI]$s) | select -ExpandProperty member|
select @{Name='members';Expression={[string]::j}}
谢谢 !
解决方案
如果您希望获得 AD 组的成员资格,这应该可以解决问题:
(Get-ADGroup 'groupName' -Properties member).member.foreach({
$_.split(',')[0].replace('CN=','')
})
这应该返回每个成员的,如果您已经拥有则samAccountName
无需使用[adsi]
ActiveDirectory Module
编辑:
所以,我假设samAccountName
并Name
为你持有相同的价值,我的错。所以这就是你如何使用 AD 模块获得你需要的东西:
(Get-ADGroup 'groupName' -Properties member).member.foreach({
(Get-ADUser $_).samAccountName
})
您还可以使用专门为此设计的 cmdlet:
(Get-ADGroupMember 'groupName').samAccountName
推荐阅读
- sql - 选择 ID 字段在另一个表中出现的次数
- python - Python multiprocessing.Processgetting 在尝试返回结果时生成 AssertionError?
- r - 如何解释路径分析中的路径系数
- javascript - jest测试总是通过,用jest检查方法请求axios
- asp.net-core - 当我尝试创建广告系列时,Google AdWords API [OperationAccessDenied.ADD_OPERATION_NOT_PERMITTED]
- http - 收到错误“类型'列表
- powershell - 如何使用powershell等待uia自动化中的按钮
- flutter - 在 Flutter 中将 Hero 小部件保持在 PageView 页面的顶部?
- angular - 可以使用什么技术来访问放置在 *ngFor 下的 DOM 元素(获取和设置值)
- javascript - Web 编译器使用 require() 将 CoffeeScript 转换为 JavaScript