I'm trying to figure out the correct syntax and whether to use Select-Object or Where-Object to accomplish what I want.
Basically, if I run a basic Get- cmdlet which returns an object's list of parameters and their values in table format I want to hide the parameters with null values.
For example, I want this output: (The output is example)
AmirOU Count
----------------- -----
tegdg 0
wfw 0
Amir 7
wtw 58
wretret 0
ergre 2
iubuibfr 0
User 593
wetwe 0
wdqdd 50
wetwe 0
Groups 0
wtw 0
ddewe 17
wetwe 0
wetwe 72
wf 11
fdgd 1
fdbd 53
rete 0
sf4t 0
4tg 0
sgsdt 0
dsfet 0
ergre 0
To look like this:
AmirOU Count
----------------- -----
Amir 7
wtw 58
ergre 2
User 593
5t5 50
grtg 17
wetwe 72
wf 11
fdgd 1
fdbd 53
This is my code:
$total = $null
Get-ADOrganizationalUnit -filter * -SearchBase 'OU=Amir,OU=test,DC=sina,DC=local' |
foreach {
if($_.distinguishedname -notmatch 'DisabledUsers|Exchange'){
$users=Get-ADUser -filter * -searchbase $_.distinguishedname -searchscope Onelevel | where-object enabled -eq true
$test=($users | measure-object).count
$total += $test
New-Object psobject -Property @{
Count= $test
AmirOU = $_.Name;
}
}
}
Write-Host "`nTotalt: $total"