raju1706
asked on
Mailbox Statistics Exchange 2007
In need a powershell query which can get the following details for users lastlogon > 60days
First Name,Last Name,Display Name,Alias, Name, Server, City, Database, Country/Region, Department,Hidden From Address Lists,Office,Phone,Postal Code,Primary SMTP Address,State Or Province,Storage Group,Recipient Type Details
I think Get-Mailbox, Get-Mailboxstastics and Get-User cmdelts have to be used.
Thanks in Advance
First Name,Last Name,Display Name,Alias, Name, Server, City, Database, Country/Region, Department,Hidden From Address Lists,Office,Phone,Postal Code,Primary SMTP Address,State Or Province,Storage Group,Recipient Type Details
I think Get-Mailbox, Get-Mailboxstastics and Get-User cmdelts have to be used.
Thanks in Advance
ASKER
@sekarc4u Thanks for the response. I cannot use Quest cmdlets.
Get-MailboxStatistics isn't too much help because it does not only show user logins on the mailbox. It shows any account that logs in, including system accounts.
Still, it can be done, it's just the first part is quite complex. I assume you want this out to a file?
Chris
Still, it can be done, it's just the first part is quite complex. I assume you want this out to a file?
# Filter to get users who have logged in within the last 60 days
$Date = (Get-Date).AddDays(-60).Date.ToFileTime()
$LdapFilter = "(&(objectClass=user)(objectCategory=person)(lastLogonTimeStamp>=$Date)(mail=*))"
$Searcher = New-Object DirectoryServices.DirectorySearcher($LdapFilter)
$Searcher.PageSize = 1000
$Searcher.FindAll() | ForEach-Object { $_.Properties["distinguishedname"][0] } | Get-User | ForEach-Object {
$Mailbox = $_ | Get-Mailbox
$_ | Select-Object FirstName, LastName, DisplayName, @{n='Alias';e={ $Mailbox.Alias }}, Name,
@{n='Server';e={ $Mailbox.ServerName }}, City, @{n='Database';e={ $Mailbox.Database }},
CountryOrRegion, Department, @{n='HiddenFromAddressLists';e={ $Mailbox.HiddenFromAddressListsEnabled }},
Office, Phone, PostalCode, WindowsEmailAddress, StateOrProvince, RecipientTypeDetails
} | Export-Csv "YourOutput.csv" -NoTypeInformation
I have not exported StorageGroup, it's included in the Database field.Chris
ASKER
@Chris.
I am a beginner in powershell , if you could explain the script it would be great.
Secondly can you also add Storage Limit Status to the script?
Thank You!!
I am a beginner in powershell , if you could explain the script it would be great.
Secondly can you also add Storage Limit Status to the script?
Thank You!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!!
# Author: Eric Woodford - <a href="http://www.ericwoodford.com
#" title="www.ericwoodford.com
#">www.ericwoodford.com
#</a> Date: 09/26/2007
# Description: Mailbox last logon information to single CSV file.
# Display Name, Last Logon Time
#
#create header for CSV file.
$CSVFilePath = 'c:\mail_LastLogon.csv'
$strDate = get-date -uformat "%Y/%m/%d"
$strDate | out-file -filepath $CSVFilePath -encoding ascii
$strOutputString = "Display Name,LastLogonTime"
$strOutputString | out-file -filepath $CSVFilePath -encoding ascii -append
#set this to match your environment.
$Computers = get-qadComputer -searchRoot 'corp.ent/Member Servers/Exchange Servers'
foreach ($computer in $computers) {
$users = Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $computer.name | Select-Object MailBoxDisplayName, LastLogonTime
# Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $computer.name | Select-Object MailBoxDisplayName, LastLogonTime
foreach ($user in $users) {
$date= [string] $user.LastLogonTime
if ($date.length -eq 0) {
$strOutputString = """"+ $user.MailBoxDisplayName + """, N/A"
}
else {
$strOutputString = """"+ $user.MailBoxDisplayName + """," + $date.substring(4,2)+"/"+$
}
$strOutputString | out-file -filepath $CSVFilePath -encoding ascii -append
}
}
http://www.ericwoodford.com/book/export/html/168
http://www.ericwoodford.com/powershell-script-2-getting-last-logon-date-exchange-mailboxes