Display all property value except blank values

This could apply to anything but specifically, I’m trying to display all ad users properties that are not blank.

I know how to display all the properties but is there a way to display only the properties that have a value. I’ve tried to filter with where-object but I’m not having any luck.

Get-ADUser USERNAME -Properties *

 

 

Give this a try:

Get-ADUser -Identity user1 -Properties * |
    ForEach-Object {
        $_.getenumerator()
    } |Where-Object -FilterScript {$_.value} |Out-string |Format-List

Getting all properties can take a long time and bandwidth if searching for all users, it is best to get the properties you need. But, I believe the above should work.

pwshliquori

It is, but would like to see how did you attempt it. Can you share the where codition you have put ?

[quote quote=151476]It is, but would like to see how did you attempt it. Can you share the where codition you have put ?

[/quote]

This is what I tried but it still returns all properties even blank values.

Get-ADUser USERNAME -Properties * | where-object {$_ -ne $null}

well, straight to the point.

Where filter decides whether the output of the preceeding cmdlet should pass through or not, here the $_ represents the full object output of Get-AdUser, which is a complex obect. But what you need is the properties which doesn’t have values. So approach on top my head is

First, get all the properties of the user
Then, identify all the properties for an AD user object.
Finally, iterate though each object and check if that property value for that particulat user object is null or not.

$User = Get-ADUser Userid -Properties *
$Property = Get-Member -MemberType Property | Select-Object -ExpandProperty Name
$Property | Foreach-Object -Process { if($null -ne $User.$_ ){$_} } #Non empty property

$Property | Foreach-Object -Process { if($null -ne $User.$_ ){$User.$_} } #Non empty property value