Giter Club home page Giter Club logo

darkseal / disable-inactive-adaccounts Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 5.0 21 KB

A small Powershell script that disables all the Active Directory user accounts inactive for more than X days.

Home Page: https://www.ryadel.com/

License: GNU General Public License v3.0

PowerShell 100.00%
windows windows-server windows-server-2019 windows-server-2016 windows-server-2012 powershell active-directory activedirectory accounts powershell-script

disable-inactive-adaccounts's Introduction

Disable-Inactive-ADAccounts

A small Powershell script that disables all the Active Directory user accounts inactive for more than X days (and/or deletes those that have been disabled more than Y days ago).

Why should we do that?

As a matter of fact, being able to automatically disable AD accounts after X days of inactivity is a good security practice. If you don't have such process up, your Active Directory could grant "permanent" access to many user accounts that should no longer be active, such as those of ex-employees or collaborators who are no longer active at your company.

Unfortunately, such feature is not (yet) supported by any version of Windows or Windows Server, at least up to Windows 10 and Windows Server 2019. That's why I ended up to develop this Powershell script.

Usage

To disable all AD users that has been inactive for 180 days or more (without deleting them):

> powershell .\Disable-Invalid-ADAccounts.ps1 -days 180

Same thing as before, plus creating a logFile.csv file containing a list of all disabled users:

> powershell .\Disable-Invalid-ADAccounts.ps1 -days 180

To disable all AD users that has been inactive for 180 days or more and also delete those that have been previously disabled more than 180 days ago.

> powershell .\Disable-Invalid-ADAccounts.ps1 -days 180 -deleteDays 180

Same thing as before, plus creating a logFile.csv file containing a list of all disabled users and a deleteLogFile.csv file containing a list of all deleted users:

> powershell .\Disable-Invalid-ADAccounts.ps1 -days 180

In case you get permissions issues when disabling/deleting AD users, you can bypass them using the Bypass Execution Policy Flag in the following way:

> powershell -ExecutionPolicy Bypass -File Disable-Invalid-ADAccounts.ps1

License

Licensed under GNU - General Public License, v3.0 - https://www.gnu.org/licenses/gpl-3.0.en.html

Credits

References

disable-inactive-adaccounts's People

Contributors

darkseal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

disable-inactive-adaccounts's Issues

Powershell Script question

Hello, I stumbled upon your AD script and I have some questions:

  1. I have a list of users that I want excluded when I want to run this script. What is the proper code for this?

  2. How do I allow this script to run automatically, say every 28 days?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.