The logic of the script is this:$date=(get-date).adddays(-7)Get-Mailbox –Filter {WhenCreated –gt $date}
- Set the variable $date equal to the current date minus 7 days.
- Get a list of mailboxes with a WhenCreated attribute greater than the date 7 days ago
Update (Dec 2015):$date=(get-date).adddays(-7)Get-ADUser –Filter {WhenCreated –gt $date}
The above syntax actually doesn't work. Not sure how I missed it when I first wrote the post. Today when I was writing a script using this syntax, it returned all mailboxes no matter what. So, the $date variable wasn't being properly evaluated. I'm leaving the above example so that people can see what syntax not to use.
Use the following syntax instead:
Apparently when building a filter with a variable, you need to enclose the whole filter in double quotes and the variable in single quotes. This syntax worked properly for me.$date=(get-date).adddays(-7)Get-Mailbox –Filter "WhenCreated –gt '$date'"
No comments:
Post a Comment