Windows Powershell Script to disable inactive AD user accounts

As part of my compliant I need to keep tabs on inactive user account. The comapny is only small right now and so easy to monitor, but as I like automating things, this fantastic script from vNucleus provides an excellent solution.

I’ve got a scheduled task to run this daily and it the checks for any accounts that have been inactive for 30 days or more and then disables them and moves them to a ‘_disabled’ OU in AD. It also sends me an email to notify me of any users that have been disabled.

View it here: accountdisablepowershell

  • RPM

    Dave,
    I cut and paste your code and like anything when you cut and paste I get errors. I resolved some but one that I can’t figure out I get from line 54.
    The error is:
    An expression was expected after ‘(‘
    sDate = Year(Now( <<<< )) &.

    • dphuk

      Hi, you may be better off copying it direct from vNucleus’s page, sometime the various blog formatting can break things.

      • rpm9906@hotmail.com

        Thanks works better. What is “&amp”. I’m assuming its calling an exe or ps1 file. If so where would I get it to get this working? Or am I way off?

        • rpm9906@hotmail.com

          forgot “&amp”

          • dphuk

            Seems the formatting has all gone to pot on this, its the ampersand, I’ll edit this and upload the working copy! :)