0

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.

Moasseman
  • 1
  • 1
  • Yes, that seems to be the case. I tried googling and searching here with as many different phrases I could think but couldn't find anyone else trying to do the same (only the other way around eg. importing from csv). Thanks LotPings – Moasseman Jun 19 '18 at 11:53
  • Use `Remove-NullProperties` from [here](https://stackoverflow.com/questions/44368990/how-do-i-get-properties-that-only-have-populated-values) like this `Get-ADUSer -Identity $usn -Properties * | Remove-NullProperties` – Vivek Kumar Singh Jun 19 '18 at 11:56
  • Thanks @VivekKumarSingh , I tried to do exactly that but ran into `"The "=" operator is missing after a named argument. At C:\Users\msk\desktop\KaikTiedot.ps1:6 char:26 + [parameter(Mandatory, <<<< ValueFromPipeline)] + Category Info : ParserError: (:) [], ParseException + FullyQualifiedErrorID : MissingEqualsInNamedArgument` – Moasseman Jun 21 '18 at 05:18

0 Answers0