获取所有具有按字段管理的空白的 AD 组

发布于 2025-01-18 08:20:46 字数 305 浏览 0 评论 0原文

我正在尝试获取所有用名称管理的空白和广告组描述的广告组。我目前在使用过滤器显示不显示结果的问题,但不确定为什么。任何帮助都将受到赞赏。

Get-ADGroup -filter * | Where-Object {$_.ManagedBy -eq ""} | Select-Object manager,description | Export-Csv -Path C:\Users\User\Desktop\AllNullManagedBy.csv -NoTypeInformation

当前脚本没有显示任何应该向几个用户显示的用户

I'm trying to get all AD groups that have a blank Managed By Name and the description of the AD group. I'm currently having issues with displaying no results using my filter, but am not sure why. Any help is appreciated.

Get-ADGroup -filter * | Where-Object {$_.ManagedBy -eq ""} | Select-Object manager,description | Export-Csv -Path C:\Users\User\Desktop\AllNullManagedBy.csv -NoTypeInformation

The current script is not showing any users which it should be showing several users

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2025-01-25 08:20:46

问题是 Get-ADGroup 默认情况下不会返回具有 ManagedBy 属性的对象,您需要请求它(-Properties ManagedBy ):

Get-ADGroup -Filter * -Properties ManagedBy, Manager, Description |
    Where-Object {-not $_.ManagedBy } | Select-Object samAccountName, Manager, Description |
    Export-Csv -Path C:\Users\User\Desktop\AllNullManagedBy.csv -NoTypeInformation

不过这个操作效率相当低,可以使用 LDAP 过滤功能

Get-ADGroup -LDAPFilter "(!managedby=*)" -Properties Manager, Description |
    Select-Object samAccountName, Manager, Description |
    Export-Csv -Path C:\Users\User\Desktop\AllNullManagedBy.csv -NoTypeInformation

作为旁注,Where-Object { $_.ManagedBy -eq "" } 可能不会返回任何结果,您将查询 ManagedBy 属性已设置并且其值等于空字符串的 AD 组,而不是过滤<强>没有该属性设置或其值为$null或空字符串{-not $_.ManagedBy }):

$null -eq '' # => False: comparison fails here
-not $null   # => True
-not ''      # => True

The problem is that Get-ADGroup does not return an object with the ManagedBy attribute by default, you need to ask for it (-Properties ManagedBy):

Get-ADGroup -Filter * -Properties ManagedBy, Manager, Description |
    Where-Object {-not $_.ManagedBy } | Select-Object samAccountName, Manager, Description |
    Export-Csv -Path C:\Users\User\Desktop\AllNullManagedBy.csv -NoTypeInformation

However, this operation is quite inefficient, you can use LDAP filtering capabilities for this:

Get-ADGroup -LDAPFilter "(!managedby=*)" -Properties Manager, Description |
    Select-Object samAccountName, Manager, Description |
    Export-Csv -Path C:\Users\User\Desktop\AllNullManagedBy.csv -NoTypeInformation

As a side note, Where-Object { $_.ManagedBy -eq "" } is likely to not return any results, you would be querying for AD Groups where their ManagedBy attribute is set and it's value is equal to an emptry string instead of filtering for groups that don't have the attribute set or it's value is $null or empty string ({-not $_.ManagedBy }):

$null -eq '' # => False: comparison fails here
-not $null   # => True
-not ''      # => True
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文