Solved

Exchange Mailboxes Detail Export

Posted on 2016-09-09
40
54 Views
Last Modified: 2016-09-14
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
0
Comment
Question by:Andy Navi
  • 17
  • 12
  • 5
  • +1
40 Comments
 
LVL 18

Expert Comment

by:Sushil Sonawane
ID: 41790825
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41790827
can you please provide the Powershell command to get all details
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41790843
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.
0
 
LVL 18

Expert Comment

by:Sushil Sonawane
ID: 41790845
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/
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41790860
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
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41790868
So you are just lazy? The explanation I provided should make it easy for you to see the correct property names.
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41790873
But i need for all mailboxes in environment
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41790907
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
0
 
LVL 18

Expert Comment

by:Sushil Sonawane
ID: 41790909
Run the below command
Get-mailbox -resultsize unlimited| FL displayname, lastlogontime | Export-Csv C:\test1.csv
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41790915
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
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41791041
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.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41791074
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..
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41791115
cant we get LastLogonTime from exchange powershell ??
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41791132
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..
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41795514
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.
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795526
subsan,


In your command, lastlogontime is showing blank.. so i need this as a main thing.
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795545
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"
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41795546
The Get-Recipient command mentioned in the comment ID: 41791132 should work, If the mailbox have a LastLogonTime associated with it.

Sample
This is same result as you get from Get_ADuser Command.
0
Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

 
LVL 4

Author Comment

by:Andy Navi
ID: 41795548
i need exactly same like this, but lastlogontime is empty for all users

i am in exchange 2013 environment and using windows powershell
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41795550
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

0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795558
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
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41795563
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

0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795564
now again when i type your first command,
still lastlogontime is blank..

and with second command same result
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41795602
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..
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795611
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
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41795615
Try..
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 -nti

Open in new window

1
 
LVL 40

Expert Comment

by:Subsun
ID: 41795619
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

0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795723
this not ggenerates the .csv file it stuck on powershell

what -NTI means in last
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41795773
lovely it worked
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41795792
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.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41795833
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})
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41796091
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.
1
 
LVL 40

Expert Comment

by:Subsun
ID: 41796839
@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!
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 41796921
Luckily I did not encouter such issues yet ;-).
0
 
LVL 4

Author Comment

by:Andy Navi
ID: 41797392
this question is already closed. thanks for helping me

i really appreciate
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41797401
It can be cancelled. You can choose the powershell answer or multiple comments as answer + assisted comments.
0
 
LVL 4

Author Closing Comment

by:Andy Navi
ID: 41797403
Thank you very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now