• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 97
  • Last Modified:

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
0
Addy Nadia
Asked:
Addy Nadia
  • 17
  • 12
  • 5
  • +1
1 Solution
 
Addy NadiaExpertAuthor Commented:
can you please provide the Powershell command to get all details
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Sushil SonawaneCommented:
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
 
Addy NadiaExpertAuthor Commented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
So you are just lazy? The explanation I provided should make it easy for you to see the correct property names.
0
 
Addy NadiaExpertAuthor Commented:
But i need for all mailboxes in environment
0
 
Addy NadiaExpertAuthor Commented:
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
 
Sushil SonawaneCommented:
Run the below command
Get-mailbox -resultsize unlimited| FL displayname, lastlogontime | Export-Csv C:\test1.csv
0
 
Addy NadiaExpertAuthor Commented:
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
 
Addy NadiaExpertAuthor Commented:
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
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
cant we get LastLogonTime from exchange powershell ??
0
 
SubsunCommented:
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
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
subsan,


In your command, lastlogontime is showing blank.. so i need this as a main thing.
0
 
Addy NadiaExpertAuthor Commented:
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
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
i need exactly same like this, but lastlogontime is empty for all users

i am in exchange 2013 environment and using windows powershell
0
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
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
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
now again when i type your first command,
still lastlogontime is blank..

and with second command same result
0
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
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
 
SubsunCommented:
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
 
SubsunCommented:
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
 
Addy NadiaExpertAuthor Commented:
this not ggenerates the .csv file it stuck on powershell

what -NTI means in last
0
 
Addy NadiaExpertAuthor Commented:
lovely it worked
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
SubsunCommented:
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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
 
SubsunCommented:
@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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Luckily I did not encouter such issues yet ;-).
0
 
Addy NadiaExpertAuthor Commented:
this question is already closed. thanks for helping me

i really appreciate
0
 
SubsunCommented:
It can be cancelled. You can choose the powershell answer or multiple comments as answer + assisted comments.
0
 
Addy NadiaExpertAuthor Commented:
Thank you very much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

  • 17
  • 12
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now