locked
Powershell ADUser query RRS feed

  • Question

  • Hi all,

    I am trying to create a script that will find users that have been disabled within a set period of time and I understand that wouldn't be possible as no time stamp is assigned to the object when the user's account is disabled/enabled. 

    However,  it only needs to be basic and not 100% accurate so what I would like to do it run a script that will find users that are disabled and their account was changed within a set period of time - this I believe would get me roughly where I want to go with this.

    What I have so far is :


    $When = ((Get-Date).AddDays(-90)).Date
    Get-ADUser -Filter {whenChanged -ge $When} -Properties whenChanged

    I am quite new to Powershell and I am not sure how to add a query on to this script that will only look for changes in accounts that have been disabled - could somebody possibly give me an idea with this one?

    Thanks guys

    Wednesday, June 10, 2015 12:45 PM

Answers

  • $When = ((Get-Date).AddDays(-90)).Date
    Get-ADUser -Filter {whenChanged -ge $When -and Enabled -eq $False} -Properties whenChanged

    Wednesday, June 10, 2015 12:55 PM

All replies

  • $When = ((Get-Date).AddDays(-90)).Date
    Get-ADUser -Filter {whenChanged -ge $When -and Enabled -eq $False} -Properties whenChanged

    Wednesday, June 10, 2015 12:55 PM
  • As simple as that!

    Worked great - thank you!!

    Wednesday, June 10, 2015 1:01 PM