如何计算foreach循环中if循环的结果 [英] How to count the result of a if loop within foreach loop
本文介绍了如何计算foreach循环中if循环的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ 123.count
但是它一直返回0 $ Groups = Get-ADGroup -Properties * -Filter * | $ $ $ $ $ $ $ $ = $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b如果($ Membership.count -eq 0){
解决方案Get-ADGroup可以在不脱离AD的情况下完成所要求的任务。
$ Count = $ count + 1
}
}
解决方案
使用Filter参数完成此操作是痛苦的。 LDAP过滤器很简单。
对于空组:
Get-ADGroup -LdapFilter(!member = *)
对于也不是嵌套的空组在其他组中:
Get-ADGroup -LdapFilter(&(!memberOf = *)(!member = *))
Is there a better way to be able to count the amounts of empty groups than using this method and then calling $count + 1 for each result? I tried to mess around with
$123.count
but it kept returning 0$Groups = Get-ADGroup -Properties * -Filter * | where { $_.Members.Count -eq 0} $123= Foreach($G In $Groups) { $Membership = Get-ADGroupMember -Identity $G.Name If($Membership.count -eq 0){ $Count = $count + 1 } }
解决方案Get-ADGroup can do much of what you ask without going away from AD.
Getting this done with the Filter parameter is painful. The LDAP filter however is simple.
For empty groups:
Get-ADGroup -LdapFilter "(!member=*)"
For empty groups which are also not nested inside other groups:
Get-ADGroup -LdapFilter "(&(!memberOf=*)(!member=*))"
这篇关于如何计算foreach循环中if循环的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文