The following code allowed me to obtain what i needed but i wondered if there was a better way to structure my query? Basically i am looking to pull out the LastLogonTime for mailbox users on Exchange as a means of identifying stale accounts, the below gives me what i need albeit i manipulate some of the rows in the spreadsheet after (to show nothing older than Feb 2020).
Thanks for the Feedback. The code makes sense, however it returns all results and not just those post 01/02/20 - same output as the command i used in effect. I tried with gt, le and ge but these came up blank.
As Olaf stated, (my kids and us love you btw,) where-object can filter the output. I’ve captured the cutoff date in a variable after casting to datetime. I tested with both 2020-02-01 and 02-01-2020. You should be able to use the -filter parameter on Get-MailboxStatistics to optimize the speed. With the Where-Object filtering, all output is gathered and then the filter is applied. I did not figure out the filter with the date yet, if I do i’ll come post it.
Thanks Doug, doesnt work for me im afraid - cannot bind LastLogonTime to the $cutoffdate variable (presumably this is because the variable is DateTime and LastLogonTime is string so cant match).
If you’re copying/pasting the code, beware that it combines the first line with the rest. I’ve added a semicolon at the end of it for others that may try to copy/paste. I also changed the path to C:\Temp\ as even with the exchange shell “ran as admin” it denied write access to C for me. Let me know if this works now. It works fine on my exchange server.
Guys thanks for the feedback here. I have tried both methods and neither seem to be working right for me.
Im due to patch this Exchange server tonight, its way out of date so potentially that is resulting in this bugging out with your commands if they are testing fine for you.
How are you running it? If you’re pasting it into powershell I’ve seen it go in out of order. If you haven’t, try opening ISE and pasting it into a blank script. Then highlight and run selection. You could also try saving it as a PS1 file and running it that way. Lastly, you can run the commands one at a time to see what isn’t working. Does get-mailboxstatistics work by itself? Maybe the command isn’t available in the powershell session you’re attempting it in?