none
Search for users created between dates. RRS feed

  • Question

  • Hi all. I am trying to build a search to be able to send a file the users are created for a date range or during the mm-yyyy month. Try with this line but it does not bring me data. Someone has had a similar theme that can help me.

    Thank you.

    Get-ADUser -Filter 'WhenCreated-Contiene "* 06-2019"' -Propiedades SamAccountName, AccountExpirationDate, WhenCreated | Export-Csv D: \ Usuarios_AD_Junio.csv

    Wednesday, June 12, 2019 4:27 AM

Answers

  • This will match all dates in year and month selected.

    $ano = 2019
    $mez = 1
    Get-ADUser -Filter * -Propiedades AccountExpirationDate,WhenCreated |
        Where-Object{ $_.WhenCreated.Year -eq $ano -and $_.whenCreated.Month -eq $mez } |
        Select-Object SamAccountName, AccountExpirationDate, WhenCreated |
        Export-Csv D: \ Usuarios_AD_Junio.csv 


    \_(ツ)_/



    • Edited by jrv Wednesday, June 12, 2019 7:52 AM
    • Proposed as answer by Peter Ziganki Wednesday, June 12, 2019 9:49 AM
    • Marked as answer by Cristian Gallegos Thursday, June 13, 2019 6:32 AM
    Wednesday, June 12, 2019 7:50 AM

All replies

  • you cannot filter a date attribute like a string.

    Get-ADUser -properties SamAccountName,accountexpirationdate,whencreated | ? { $_.whenCreated -ge (get-date "01.06.2019")}|Select Samaccountname,whenCreated,SamAccountName,accountexpirationdate| Export-CSV Accounts.csv


    Please remember to mark the replies as answers if they helped.

    Wednesday, June 12, 2019 6:07 AM
  • This will match all dates in year and month selected.

    $ano = 2019
    $mez = 1
    Get-ADUser -Filter * -Propiedades AccountExpirationDate,WhenCreated |
        Where-Object{ $_.WhenCreated.Year -eq $ano -and $_.whenCreated.Month -eq $mez } |
        Select-Object SamAccountName, AccountExpirationDate, WhenCreated |
        Export-Csv D: \ Usuarios_AD_Junio.csv 


    \_(ツ)_/



    • Edited by jrv Wednesday, June 12, 2019 7:52 AM
    • Proposed as answer by Peter Ziganki Wednesday, June 12, 2019 9:49 AM
    • Marked as answer by Cristian Gallegos Thursday, June 13, 2019 6:32 AM
    Wednesday, June 12, 2019 7:50 AM
  • The following will be much faster

    $ano = 2019
    $mez = 6
    $start = [datetime]::New($ano,$mez,1)
    $end = $start.AddMonths(1)
    $filter = "Created -ge '$start' -and Created -lt '$end'"
    Get-AdUser -filter $filter -Propiedades AccountExpirationDate, WhenCreated
    


    \_(ツ)_/

    • Proposed as answer by Peter Ziganki Wednesday, June 12, 2019 9:50 AM
    Wednesday, June 12, 2019 8:14 AM
  • Hello
    It works perfect, thank you very much for your help ;-)

    The values ​​of:
    $ano = 2019
    $mez = 6
    Can they enter with an input? Its ready!! Thank you very much!!!! :-)


    Thursday, June 13, 2019 6:23 AM
  • Hi
    It works perfect, only I need to bring users between two dates or a whole month. Thank you.

    Cristian.

    Thursday, June 13, 2019 6:26 AM
  • This only brings me data for January 2019. Regards.

    Cristian.

    Thursday, June 13, 2019 6:34 AM
  • This only brings me data for January 2019. Regards.

    Cristian.

    You fail to say what code you are using to get that.  We can't guess.


    \_(ツ)_/

    Thursday, June 13, 2019 8:45 AM