本文介绍了组合 PowerShell 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了两个脚本,它们为我提供了所需的独立输出,但我不确定如何将它们组合在一起以提供组合输出.
I've written two scripts that give me the independent output that I need, but am not sure how to put them together to give me the combined output.
返回特定 OU 中所有活动用户的计数
Returns the count of all of the active users in a particular OU
(Get-ADUser -searchbase "OU=OU, DC=domain, DC=com" -filter * |Where {$_.enabled -eq "True"}).count
返回在描述属性中具有字符串"的同一上述 OU 下的 OU.
Returns the OU's underneath the same above OU that have "string" in the description property.
Get-ADOrganizationalUnit -searchbase "OU=OU, DC=domain, DC=com" -filter * -Properties description | where {$_.description -eq "string"}
我想要完成的是让脚本为我提供 OU 下在 description 属性中具有字符串"的所有活动用户的计数.
What I'm trying to accomplish is for the script to give me a count of all of the active users underneath the OU's that have "string" in the description property.
推荐答案
我认为这是实现目标的最简单方法
I think this is the easiest way to achieve your goal
$OUs = Get-ADOrganizationalUnit -searchbase "OU=OU, DC=domain, DC=com" -filter * -Properties description | where {$_.description -eq "string"}
ForEach ($OU in $OUs) {
$count = (Get-ADUser -searchbase $OU -filter * | Where {$_.enabled -eq "True"}).count
Write-Host "OU $OU has $count users"
}
结果是
OU OU=foo,DC=domain,DC=com has 6 users
OU OU=Computers,OU=foo,DC=domain,DC=com has 0 users
OU OU=Users,OU=foo,DC=domain,DC=com has 6 users
OU OU=Groups,OU=foo,DC=domain,DC=com has 0 users
这篇关于组合 PowerShell 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!