none
command side effect? RRS feed

  • Question

  • yesterday i used this command to list users created in the past 7 days:

    Get-ADUser -Filter { whenCreated -ge 7 } -Properties whenCreated

    and i was able to get a list for the past 7 days.

    today, when i issued same command nothing gets returned. so i did a,

    Get-ADUser -Filter * | fl whenCreated, name

    only to find out why. the "whenCreated" is null.

    does thes command i used have some kind of side-effect? i even tried 30 days and nothing gets returned.

    Thursday, January 28, 2016 5:15 AM

Answers

  • "whenCreated" is a date and not a number so your method will not work. 

    Note that this is also true: [datetime]::Today -ge 7

    Get-AdUser -filter * -Properties whenCreated | fl whenCreated, name


    \_(ツ)_/


    • Edited by jrv Thursday, January 28, 2016 9:05 AM
    • Marked as answer by Reno Mardo Thursday, January 28, 2016 11:36 AM
    Thursday, January 28, 2016 8:55 AM

All replies

  • "whenCreated" is a date and not a number so your method will not work. 

    Note that this is also true: [datetime]::Today -ge 7

    Get-AdUser -filter * -Properties whenCreated | fl whenCreated, name


    \_(ツ)_/


    • Edited by jrv Thursday, January 28, 2016 9:05 AM
    • Marked as answer by Reno Mardo Thursday, January 28, 2016 11:36 AM
    Thursday, January 28, 2016 8:55 AM
  • Hi Reno,

    Get-* cmdlets don't change anything on the server. But it might overload the server, by querying lots of users.

    Whencreated is not listed as the default properties on Get-ADUser hence as shown by Jrv you need to use -Properties * or -Properties Whencreated for it to work.

    Get-ADUser satyajit -Properties * | fl whencreated

    Get-ADUser -Filter * -Properties WhenCreated | ft whenCreated, name


    Regards,

    Satyajit

    Please“Vote As Helpful” if you find my contribution useful or “MarkAs Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.






    • Edited by Satyajit321 Thursday, January 28, 2016 11:14 AM
    Thursday, January 28, 2016 11:12 AM
  • You could use a filter similar to below (for Jan. 20, 2016):

    Get-ADUser -Filter {whenCreated -ge '20160120000000.0Z'} -Properties whenCreated

    where the date is in the form 'YYYYMMDDhhmmss.0Z'. You would just need to modify the date each day.

    Richard Mueller - MVP Enterprise Mobility (Directory Services)

    Thursday, January 28, 2016 11:38 AM
    Moderator
  • ahh much better! :) thanks.
    Thursday, January 28, 2016 11:52 AM
  • As I noted; "whenCreated" is a date object in PowerShell.

    $d=[datetime]::Today.AddDays(-30)
    Get-AdUser -filter {whenCreated -ge $d} -Prop whenCreated | select Name, whenCreated

    Richards works because both LDAP and object forms are allowed in MS  filters


    \_(ツ)_/


    • Edited by jrv Thursday, January 28, 2016 11:57 AM
    Thursday, January 28, 2016 11:53 AM