How to specify in powershell that property in AD is not set


Please advice, how can I specify that value of propert in AD is "not set".

I tried $null etc..

@{N='AccountExpires';E={if  ((get-date ($_.accountexpires)) -eq $null) {write 'NOT SET!'}  else {(((get-date ($_.accountexpires)).adddays(-1)).Tostring(“dd.MM.yyyy”)) }}}

Any idea, many thanks
Who is Participating?
soostibiConnect With a Mentor Commented:
The other option is to use the AccountExpirationDate attribute, with this you can use:

@{N='AccountExpires';E={if  ($_.accountexpirationdate -eq $null) {write 'NOT SET!'}  else {($_.accountexpirationdate.adddays(-1).Tostring(“dd.MM.yyyy”)) }}}
Unfortunately this depends on the data type. For this specific attribute "never" means 9223372036854775807, so if the value of accountexpires is that number, that means it never expires.
Radim88Author Commented:
Thx a lot :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.