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

Posted on 2011-05-12
Last Modified: 2012-05-11


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
Question by:Radim88
    LVL 13

    Expert Comment

    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.
    LVL 13

    Accepted Solution

    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”)) }}}

    Author Closing Comment

    Thx a lot :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
    "Migrate" an SMTP relay receive connector to a new server using info from an old server.
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now