none
Looking for a Powershell Script that idenetifies all user accounts created in the last month RRS feed

  • Question

  • I'm Looking for a Powershell Script that idenetifies all user accounts created in the last month, week, day.  We are trying to determine when an Active Directory Attribute started getting modified.  The attribute is employeeID.  

    Another option would be to achieve this same goal using either dsquery or dsget in a command.

    Thanks,

    Kevin C.

    Wednesday, October 29, 2014 12:09 AM

Answers

All replies

  • Hi Kevin,

    You can filter on the Created property of AD accounts by using the -Filter parameter of Get-ADUser.

    Example:

    $cutoff = (Get-Date).AddDays(-30)
    
    Get-ADUser -Filter "Created -gt '$cutoff'" -Properties EmployeeID, Created |
        Select SamAccountName,EmployeeID,Created

    Link to syntax:

    http://ss64.com/ps/get-aduser.html


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Wednesday, October 29, 2014 1:49 AM
  • if you simply want to get all users created in last 07 days , below code will work great

    Import-Module -Name activedirectory
    $week=(Get-Date).adddays(-7)
    $today=(Get-Date).tostring()
    Get-ADUser -Filter * -Properties * | where {$_.whencreated -ge $week } | select name,whencreated | Export-Csv E:\newusers.csv

    thanks,

    please mark and vote helpful if works

     
    Wednesday, October 29, 2014 1:45 PM
  • if you simply want to get all users created in last 07 days , below code will work great

    <snip>

    I highly recommend using the -Filter syntax I posted above. Your version returns all users (and all properties) and then filters client side.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Wednesday, October 29, 2014 1:53 PM
  • Thanks.  This syntax seemed to do the trick for me.  Appreciate everyone's responses.  I am new to Powershell and continute to try to build my knowledge.    I will use this going forward. 

    Thanks again,

    Kevin C.

    Wednesday, October 29, 2014 2:35 PM
  • Thanks.  This syntax seemed to do the trick for me.  Appreciate everyone's responses.  I am new to Powershell and continute to try to build my knowledge.    I will use this going forward. 

    Thanks again,

    Kevin C.

    I again highly recommend not using the post you've marked as an answer.


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Wednesday, October 29, 2014 2:37 PM
  • Mikes version will save you a lot of staring at screen time.

    $script = { $cutoff = (Get-Date).AddDays(-30)
    
    Get-ADUser -Filter "Created -gt '$cutoff'" -Properties EmployeeID, Created |
        Select SamAccountName,EmployeeID,Created}
    
    PS C:\powershell> Measure-Command $script
    
    
    Days              : 0
    Hours             : 0
    Minutes           : 0
    Seconds           : 0
    Milliseconds      : 852
    Ticks             : 8520505
    TotalDays         : 9.86169560185185E-06
    TotalHours        : 0.000236680694444444
    TotalMinutes      : 0.0142008416666667
    TotalSeconds      : 0.8520505
    TotalMilliseconds : 852.0505

    $script = { $week=(Get-Date).adddays(-7)
    $today=(Get-Date).tostring()
    Get-ADUser -Filter * -Properties * | where {$_.whencreated -ge $week } | select name,whencreated }
    
    PS C:\powershell> Measure-Command $script
    
    
    Days              : 0
    Hours             : 0
    Minutes           : 1
    Seconds           : 14
    Milliseconds      : 452
    Ticks             : 744529526
    TotalDays         : 0.000861723988425926
    TotalHours        : 0.0206813757222222
    TotalMinutes      : 1.24088254333333
    TotalSeconds      : 74.4529526
    TotalMilliseconds : 74452.9526


    Wednesday, October 29, 2014 3:22 PM
  • Right :(

    Thursday, October 30, 2014 6:56 AM