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


Hello,

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
Radim88Asked:
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”)) }}}
0
 
soostibiCommented:
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.
0
 
Radim88Author Commented:
Thx a lot :-)
0
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.