获取所有字段管理空白的广告组

问题描述 投票:0回答:1

我正在尝试获取所有 Managed By Name 和 AD 组描述为空白的 AD 组。我目前遇到使用过滤器不显示任何结果的问题,但不确定原因。任何帮助表示赞赏。

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

当前脚本没有显示任何用户,它应该显示多个用户

powershell active-directory attributes where-object
1个回答
4
投票

问题是

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
属性 已设置 且其值等于 empry string 而不是过滤组的广告组没有属性集或者它的值为
$null
或空字符串
{-not $_.ManagedBy }
):

$null -eq '' # => False: comparison fails here
-not $null   # => True
-not ''      # => True
© www.soinside.com 2019 - 2024. All rights reserved.