Powershell、筛选器和组合属性

Powershell、筛选器和组合属性,powershell,Powershell,我有一个广告组,有其他广告组作为成员。其中一些组也可能有“子组”。我希望递归地遍历这个组,并找到关于该组中用户的几个问题的答案。例如: 用户X在整个组中是否已“启用” User-X的帐户是否在任何属性中具有值:AccountExpirationDate、accountExpires和Deleted 我希望显示的结果包含以下属性:DisplayName、SamAccountName、AccountExpirationDate、accountExpires、Deleted和enabled(从组对

我有一个广告组,有其他广告组作为成员。其中一些组也可能有“子组”。我希望递归地遍历这个组,并找到关于该组中用户的几个问题的答案。例如:

  • 用户X在整个组中是否已“启用”
  • User-X的帐户是否在任何属性中具有值:AccountExpirationDate、accountExpires和Deleted
我希望显示的结果包含以下属性:DisplayName、SamAccountName、AccountExpirationDate、accountExpires、Deleted和enabled(从组对象)

我已尝试通过“添加成员”从get-ADgroupMember插入“enabled”值,但出现错误:

Add-Member : Cannot add a member with the name "enabled" because a member with that name already exists. If you want to over
write the member anyway, use the Force parameter to overwrite it.
。。。但据我所知,没有这样的因素。我已经将addmember中的成员重命名为几个非常独特的东西,但仍然会出现相同的错误

我目前的尝试是:

Import-Module ActiveDirectory

get-adgroupmember -Identity "My big AD group of groups" -recursive |
    Where-Object -FilterScript {($_.ObjectClass -eq 'user')} |
    ForEach-Object {
        $enabled = $_.enebled
        Get-ADUser `
            -Filter {(name -eq $_.name)} `
            -Properties DisplayName,SamAccountName,AccountExpirationDate,accountExpires,Deleted |
            Add-Member -Name "myITGGroupEnabled" -Value $enabled -MemberType NoteProperty |
            Where-Object `
                -FilterScript {
                    ($_.AccountExpirationDate -lt [datetime]::now) `
                    -OR ($_.accountExpires -eq $true) `
                    -OR ($_.Deleted -eq $true) `
                    -OR ($_.myITGGroupEnabled -eq $false)
                }
            Select-Object DisplayName,SamAccountName,AccountExpirationDate,accountExpires,Deleted,GroupEnabled
        break
    }

我迷路了。想法?

我想你需要的只是一个新的PSObject。像这样:

    ...
    Get-AdUser -Filter {name -eq $_.name} -Properties ....  | % { 
     If  ( ($_.AccountExpirationDate -lt [datetime]::now) `
                    -OR ($_.accountExpires -eq $true) `
                    -OR ($_.Deleted -eq $true) `
                    -OR ($_.myITGGroupEnabled -eq $false)) { 

       New-Object PSObject -Property @{MyITGGRoupEnabled=$enabled}
     }           
    }