powershell - 使用 Powershell 从 AD 组获取嵌套 CN 值
问题描述
我一直在尝试CN
从 AD 组的属性中获取值managedBy
,这是我获取组的代码
Get-ADGroup CACAL-ER-Marketing -Properties SamAccountName, managedBy, Name, Description, GroupCategory |
Select-Object SamAccountName, managedBy, Name, Description, GroupCategory
输出:
SamAccountName : CACAL-ER-Marketing
managedBy : CN=Diane Dela Torre,OU=1-Mail Archive Needed,OU=User Archive,DC=hrbl,DC=net
Name : CACAL-ER-Marketing
Description :
GroupCategory : Security
我想得到的是'Diane Dela Torre'值,我尝试转换mananagedBy
为Json,但它输出它不是一个cmdlet,比如
Get-ADGroup CACAL-ER-Marketing -Properties SamAccountName, managedBy, Name, Description, GroupCategory |
Select-Object SamAccountName, (managedBy | ConvertTo-Json).CN, Name, Description, GroupCategory
managedBy : The term 'managedBy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:2 char:32
+ Select-Object SamAccountName, (managedBy | ConvertTo-Json).CN, Name, ...
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (managedBy:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
解决方案
由于该managedBy
属性是DistinguishedName
用户的,而不是在其上使用正则表达式来获取该用户的显示名称,我将使用 Get-ADUser 来执行此操作。
Get-ADGroup CACAL-ER-Marketing -Properties SamAccountName, managedBy, Name, Description, GroupCategory |
Select-Object SamAccountName,
@{Name = 'ManagedBy'; Expression = { (Get-ADUser -Identity $_.managedBy -Properties DisplayName).DisplayName }},
Name, Description, GroupCategory
推荐阅读
- actions-on-google - 提交 Google Assistant 进行 Alpha 测试时是否有地域限制?
- service-worker - 如何手动终止正在运行的 Service Worker
- python - Django - 删除按钮未重定向到正确的路径
- mvvm - 在 c# 中更改项目源时,UWP DataGrid 不会更新 UI
- javascript - 按观看次数和日期排序的趋势
- oauth-2.0 - Auth0 社交登录角色分配
- entity-framework - 将 linq 用于 Npgsql EntityFramework6 模型时引发 SocketException
- tensorflow - 张量流如何计算`.linalg.eigh`的梯度?
- python - 我应该如何用“np.around”方法解决我的问题?
- asp.net - 有没有办法阻止 ASP.NET Core 应用程序发送任何电子邮件?