I'm using Get-ADUser -Identity X to list all attributes belonging to X in an AD in a text file, but it also contains "empty" fields which I'd like to exclude
Import-Module ActiveDirectory
$usn = Read-Host -Prompt 'Enter username (1+7)'
Get-ADUSer -Identity $usn -Properties * | out-file .\testi.txt
As an example, this would list (partial example)
AccountExpirationDate :
accountExpires : 9223372036854775807
AccountLockoutTime :
AccountNotDelegated : False
In the example, I'd like it to not list AccountExpirationDate and AccountLockoutTime at all since both are "empty" but I can't find any way of doing so.
I tried using "where-object" but that didn't affect the properties but rather the whole list. I'm still practically an infant when it comes to pshell as you might notice, so thanks to anyone who spends even a second or two on me.