Get-ADGroup 使用 Where-Object 命令let

huangapple go评论51阅读模式
英文:

Get-ADGroup with Where-Object cmdlet

问题

I can help you with the translation:

我一直在尝试创建一个脚本来查找一个组中缺失的“Member of”组。有人可以帮助我编写 `Where-Object` 命令,因为我真的不知道这是如何工作的。

这是我已经有的内容:

$MissingGroup = "gg-s-MissingGroup"

$Group = Get-ADGroup -Filter 'Name -like "gg-s-*-Group"' -SearchBase "OU=xxxxxxx,DC=xxxxxxxxx,DC=xx" | Format-Table Name


我需要一个 `$Group` 列表,其中 `$MissingGroup` 不是其“Member of”之一。

请注意,我只提供翻译,不回答问题或提供代码部分的翻译。

英文:

I've been trying to create a script to find a missing "Member of" Group in a Group. Can someone help me write the Where-Object cmdlet because I really don't know how this works.

This is what I already have:

$MissingGroup = "gg-s-MissingGroup"

$Group = Get-ADGroup -Filter 'Name -like "gg-s-*-Group"' -SearchBase "OU=xxxxxxx,DC=xxxxxxxxx,DC=xx" | Format-Table Name

I need the a list of the $Group where the $MissingGroup is NOT a "Member of" it.

答案1

得分: 2

你不需要 Where-Object 进行这个操作,你可以并且应该使用 Active Directory Filter

英文:

You don't need Where-Object for this, you can and should do it with the Active Directory Filter:

$MissingGroup = 'gg-s-MissingGroup'

$getADGroupSplat = @{
    # find all groups where `$MissingGroup` is NOT a member of
    LDAPFilter = '(!memberof={0})' -f (Get-ADGroup $MissingGroup).DistinguishedName
    SearchBase = 'OU=xxxxxxx,DC=xxxxxxxxx,DC=xx'
}

$Group = Get-ADGroup @getADGroupSplat

huangapple
  • 本文由 发表于 2023年4月17日 22:23:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定