Link to home
Start Free TrialLog in
Avatar of Andy Andy
Andy AndyFlag for India

asked on

Exchange Mailboxes Detail Export

Hello Team,

Could you please suggest the command to pull the following details in Exhcange 2013 through powershell.

DisplayName.
FirstName
LastName,
Organizational Unit
MailboxType
LastLogontimeStamp

Appreciate, if someone can suggest ASAP

Thanks,
Andy
Avatar of Andy Andy

ASKER

can you please provide the Powershell command to get all details
Avatar of Qlemo
Why don't you find that out yourself? It doesn't help you long-term if we just provide the ready-to-use command. Building the correct statements is always along this:

You check which cmdlets could retrieve the desired information. With Exchange you start with Get-Mailbox whenever mailboxes are concerned.
Then you check what the results are:
Get-Mailbox OneOfYourMailboxes | fl *

Open in new window

That displays the available info for a single mailbox. Now use the property names as displayed.
Get-Mailbox | Select DisplayName. FirstName, LastName, OrganizationalUnit, MailboxType, LastLogontimeStamp

Open in new window

I didn't check if the property names I used are the correct ones, but you should get the idea.
get-mailbox -resultsize unlimited | FL  DisplayName, FirstName, LastName, Organizational Unit, MailboxType, LastLogontimeStamp


OR

Get-MailBox | Format-List *

For info refer below link:

http://exchangeserverpro.com/powershell-tip-get-list-top-exchange-server-mailboxes-size/
i used the command, but it didnt helped

ok i have feteched all other details.

can only i get Displayname and Lastlogontime for all users
So you are just lazy? The explanation I provided should make it easy for you to see the correct property names.
But i need for all mailboxes in environment
i have used this command

Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:\test1.csv

but it fetch the report of users who logged on server, not user logontime, when they accessed there mailbox
Run the below command
Get-mailbox -resultsize unlimited| FL displayname, lastlogontime | Export-Csv C:\test1.csv
i think this need to be fetched through get-mailboxstatistics, because that can give the lastlogontime

but i didn't get the details of all 20000 mailboxes in environment
Qlemo, if i need to searched by own, then what will experts will do ????

i have doubt, that is why i posted question here. because when i tried to use any of above commands.
i got the lastlogontime of user who logged on server. not of user logontime , which state, when user last accessed his mailbox

Hope you get the question properly now.
Get-mailbox may not output the FirstName, LastName details..
Try.. Get-Recipient
Get-Recipient -Resultsize unlimited | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails

Open in new window

i got the lastlogontime of user who logged on server. not of user logontime , which state, when user last accessed his mailbox
LastLogonTime is fetched from domain controller, it doesn't differentiate whether it's mailbox login or computer login. However if the LastLoggedOnUserAccount is present then we can safely assume the user is logged in to mailbox.

You can test by Login to a test mailbox to confirm the same..
cant we get LastLogonTime from exchange powershell ??
Get-MailboxStatistics should show it...
Get-MailboxStatistics User | Select Last*

Open in new window


If you need all details as a single command result, then you need to make a custom property
Ref : https://blogs.technet.microsoft.com/josebda/2014/04/19/powershell-tips-for-building-objects-with-custom-properties-and-special-formatting/
Example..
Get-Recipient -Resultsize unlimited | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={($_| Get-MailboxStatistics).LastLogonTime}}

Open in new window


Let us know if you have any questions..
In my opinion, The details posted by experts have good information to solve your request. If you find a different solution please post it and close this question by accepting your comments.
subsan,


In your command, lastlogontime is showing blank.. so i need this as a main thing.
i have exported all required attributes through below command from Powershell


csvde -f EU.csv -s domainname -p subtree -d "dc=domain,dc=ent,dc=domain,dc=com" -r "(&(objectCategory=person)(objectClass=User)(!userAccountControl:1.2.840.113556.1.4.803:=2))" -l "givenName,sn,sAMAccountName,displayName,distinguishedName,userAccountControl,lastLogon,Lastlogontimestamp"
The Get-Recipient command mentioned in the comment ID: 41791132 should work, If the mailbox have a LastLogonTime associated with it.

User generated image
This is same result as you get from Get_ADuser Command.
i need exactly same like this, but lastlogontime is empty for all users

i am in exchange 2013 environment and using windows powershell
It should work in Exchange 2013, are you using the exact command which I posted?
If yes post the result of following command for one user
Get-Recipient UserA | Get-MailboxStatistics | FL Last*

Open in new window

yes now i got the result of this


LastLoggedOnUserAccount :
LastLogoffTime          :
LastLogonTime           : 9/13/2016 9:45:22 AM

can you suggest, what was the mistake in old command
I am not sure yet.. Try following commands and see.. if it gives desired result..
Get-Recipient UserA | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={($_| Get-MailboxStatistics).LastLogonTime}}

Open in new window

And
Get-Recipient -Resultsize unlimited | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={($_| Get-MailboxStatistics).LastLogonTime}}

Open in new window

now again when i type your first command,
still lastlogontime is blank..

and with second command same result
That's really strange... Does any of following command give result?
Get-Recipient UserA | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={(Get-MailboxStatistics $_.Alias).LastLogonTime}}

Open in new window


Foreach ($user in (Get-Recipient UserA)){ 
$St = $user | Get-MailboxStatistics 
$User | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={$St.LastLogonTime}}
}

Open in new window


If not post the screenshot of the commands which you run and the result, let me se if I can figure it out what is wrong..
yes now , with the first command i got the results, which required

Get-Recipient ngupta2 | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={(Get-MailboxStatistics $_.Alias).LastLogonTime}}

can we make it for all mailboxes in environment and export in CSV file
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or try..

$(Foreach ($user in (Get-Recipient -Resultsize unlimited | ?{$_.RecipientTypeDetails -eq "UserMailbox"})){
$user | Select DisplayName, FirstName, LastName, OrganizationalUnit,RecipientTypeDetails,@{N="LastLogonTime";E={(Get-MailboxStatistics $_.Alias).LastLogonTime}}
})| Export-csv C:\Temp\report.csv -nti

Open in new window

this not ggenerates the .csv file it stuck on powershell

what -NTI means in last
lovely it worked
As written the file will be generated only after the complete pipeline including the for loop has been processed and finished. Better:
Get-Recipient -Resultsize unlimited |
  ? { $_.RecipientTypeDetails -eq "UserMailbox" } |
  Select DisplayName, FirstName, LastName, OrganizationalUnit, RecipientTypeDetails,
         @{N="LastLogonTime";E={(Get-MailboxStatistics $_.Alias).LastLogonTime}} |
  Export-csv C:\Temp\report.csv -NoType

Open in new window

-NTI or -NoType are short for -NoTypeInformation. Without the CSV export contains a first line with the data types of each column, and that is usually unwanted, because AFAIK only PowerShell can make use of that type info on import.
FYI.. Direct pipeline sometime wont work well with Exchange Management Shell, I have seen issues like values from result are missing or it may throw errors like 'Pipeline not executed because a pipeline is already executing'. It seems to be a bug, I have seen it from Exchange 2007 onwards.. Work around is to use ForEach (ForEach (item In collection) {ScriptBlock})
The "pipeline" error results from remote shell not being able to use a pipe in a pipe. One level of pipe works well for me. So the trick is rather to use a foreach statement inside the pipeline, and no pipeline inside of the outer loop.
@Qlemo, Right it's related to PowerShell remoting. But the it's weird that the error is kind of random, same code which gives error may work if you run it for second or third  time. In this question the code which I gave initially works well in my Exchange 2013 server but it doesn't worked for Andy Navi.. :-)

Following code fails randomly even if i runs it locally on exchange server..
Get-Mailbox -OrganizationalUnit Admin | %{ New-InboxRule -Name Attach -Mailbox $_ -HasAttachment $true -MarkImportance High }

Open in new window

Following code always work..
$sales = Get-Mailbox -OrganizationalUnit Admin
$sales | %{New-InboxRule -Name Attach -Mailbox $_ -HasAttachment $true -MarkImportance High}

Open in new window

I will try your suggestion..

@Andy Navi, Your comment  ID: 41795545 is not a PowerShell answer. So if you are OK, you can choose the PowerShell answer which worked for you!
Luckily I did not encouter such issues yet ;-).
this question is already closed. thanks for helping me

i really appreciate
It can be cancelled. You can choose the powershell answer or multiple comments as answer + assisted comments.
Thank you very much