英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论