PowerShell: Active users last 30 days (with custom columns)
Hello!
I would like to write a PS query that shows the active mailbox users from the last 30 days. I'd like to paste this query into excel with the following columns: Display name, lastlogontime and the quota of the mailbox.
What I could write by myself:
get-mailboxserver | Get-MailboxStatistics | Where {($_.LastLogonTime -gt (get-date).adddays(-30))} | sort-object lastlogontime | format-table Displayname,lastlogontime
I think I should paste the " -resultsize unlimited" after the mailboxstatics but if I do so I get an error.
And I got no idea how could I put the quota size into this query.
I use exchange2007...
Thanks in advance!
Balázs Fabi from hungary
August 11th, 2010 3:57pm
Not tested:
$stats = @()
foreach ($mbx in get-mailbox -resultsize unlimited){
if ((get-mailboxstatistics $mbx).lastlogontime -gt (get-date).adddays(-30)){
$stat = get-mailboxstatistics $mbx | select displayname,lastlogontime
$stat | add-member -membertype noteproperty -name "Quota" -value "$(mbx.ProhibitSendReceiveQuota)"
$stats += $stat
}
}
$stats[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 11th, 2010 4:35pm
thanks, but it not really works:
"The term 'mbx.ProhibitSendReceiveQuota' is not recognized as a cmdlet, function
, operable program, or script file. Verify the term and try again.
At line:1 char:28
+ mbx.ProhibitSendReceiveQuota <<<<
The term 'mbx.ProhibitSendReceiveQuota' is not recognized as a cmdlet, function
, operable program, or script file. Verify the term and try again.
At line:1 char:28
+ mbx.ProhibitSendReceiveQuota <<<<"
August 11th, 2010 5:12pm
Typo fail. It should work better with $mbx.ProhibitSendReceiveQuota
$stats = @()
foreach ($mbx in get-mailbox -resultsize unlimited){
if ((get-mailboxstatistics $mbx).lastlogontime -gt (get-date).adddays(-30)){
$stat = get-mailboxstatistics $mbx | select displayname,lastlogontime
$stat | add-member -membertype noteproperty -name "Quota" -value "$($mbx.ProhibitSendReceiveQuota)"
$stats += $stat
}
}
$stats[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 11th, 2010 5:27pm
It works thank you very much!
It's my last little question:
There is a lot of mailbox which has been never logged on to, and I get a lot of warning like that:
"WARNING: There is no data to return for the specified mailbox
'XY', because it has not been logged on to.
Is there a solution to filter that mailboxes which has no logged on data?
August 12th, 2010 11:06am
I don't get that error testing against one of my mailboxes that hasn't been logged on to, so I can't really test it, but see if this works:
$stats = @()
foreach ($mbx in get-mailbox -resultsize unlimited){
if ((get-mailboxstatistics $mbx).lastlogontime){
if ((get-mailboxstatistics $mbx).lastlogontime -gt (get-date).adddays(-30)){
$stat = get-mailboxstatistics $mbx | select displayname,lastlogontime
$stat | add-member -membertype noteproperty -name "Quota" -value "$($mbx.ProhibitSendReceiveQuota)"
$stats += $stat
}
}
}
$stats[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 12th, 2010 3:39pm
:( a lot of yellow warning like this:
WARNING: There is no data to return for the specified mailbox
'abc.xyz/users/xy/NLaci@tesztbbu64', because it
has not been logged on to.
thanks for your help
August 12th, 2010 4:56pm
Are you getting the errors on the get-mailbox, or on the get-mailboxstatistics? [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
August 12th, 2010 5:23pm
No, if I run these commands, I don't get any warning.
August 16th, 2010 10:43am