?
Solved

combining get-mailbox and Get-LogonStatistics

Posted on 2011-10-10
9
Medium Priority
?
1,788 Views
Last Modified: 2012-05-12
I want to dump the following about a user:
items in folders
folder sizes
Outlook version
whether they are in cached or online mode.  
I currently do this with 2 powershell command:

get-mailbox <USER> | Get-MailboxFolderStatistics | select-object Identity,Folderpath,FolderType,itemsinfolder,@{Name="FolderSize KB";expression={$_.folderSize.toKB()}} |

Get-LogonStatistics <USER> | select windows2000account, databasename, clientversion, clientmode

Is there a way to combine these so that i just have one command to run?

Thanks!
0
Comment
Question by:suelizy
  • 4
  • 3
  • 2
9 Comments
 
LVL 43

Expert Comment

by:Adam Brown
ID: 36945791
Yep. I've attached a script that will prompt you for a username and then output what you want in a nice readable format.
$user = read-host "Enter Username"
get-mailbox $user | foreach {
$Statistics = Get-MailboxFolderStatistics $user | select-object Identity,Folderpath,FolderType,itemsinfolder,@{Name="FolderSize KB";expression={$_.folderSize.toKB()}} 
$LogonStats = Get-LogonStatistics $user | select windows2000account, databasename, clientversion, clientmode 
$statistics
$logonstats
}

Open in new window

0
 
LVL 9

Expert Comment

by:chrismerritt
ID: 36951822
I'll ask the same thing I asked when this came up last time, how do you know which value in Get-LogonStatistics to use if multiple different lines are returned?

In my experience, Get-LogonStatistics returns multiple entries for users connected multiple times, i.e. mobile device, outlook, mac etc. Which one is the right one to pull back into your report?

Also Get-MailboxFolderStatistics returns one line per folder, how are you going to put these into one report? how should it look?
0
 

Author Comment

by:suelizy
ID: 36951926
acbrown:  how can i export this to a csv?  I added export-csv to the end of the script and it only exported 1 of the 2 commands.

chrismerritt:  regarding get-logonstatistics, if i get multiple lines i plan on looking at them and deleting the ones i don't care about.   This is much easier when its exported to csv to edit in excel.  Get-MailboxFolderStatistics looks fine when you export to .csv.  In csv there would be a column for each item:  identity:     Folder path:     ItemsInFolder     FolderSizeKB

Thanks!
Susan
0
A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

 
LVL 9

Expert Comment

by:chrismerritt
ID: 36951976
So you are happy to have both commands exported to seperate CSV files? I can't see how they can be combined into one CSV export is all.

If that's the case this is easy to do, let me know.
0
 

Author Comment

by:suelizy
ID: 36952010
separate would be preferred, but i can make 2 work.

Thanks!

Susan
0
 
LVL 43

Expert Comment

by:Adam Brown
ID: 36952096
at the point where the variables are called, add a pipe and the export command, but that only works if you run this against one user at a time. If you're okay with that, you can name the file after the username by setting <filename> as "$username.csv"
$statistics | export-csv <filename>
$logonstats | export-csv <filename>

Open in new window

0
 
LVL 9

Expert Comment

by:chrismerritt
ID: 36952120
"separate would be preferred, but i can make 2 work".

Hehe, seperate preffered but you can make 2 work? I thought that seperate and having two different exports was also considered seperate. You have officially confused me! :)

As the guy above said pipe to Export-CSV and put your filename in.

I would also add the -NoType switch like this:

get-mailbox <USER> | Get-MailboxFolderStatistics | select-object Identity,Folderpath,FolderType,itemsinfolder,@{Name="FolderSize KB";expression={$_.folderSize.toKB()}} | Export-CSV "C:\Some Folder\SomeFile1.csv" -NoType

Get-LogonStatistics <USER> | select windows2000account, databasename, clientversion, clientmode | Export-CSV "C:\Some Folder\SomeFile2.csv" -NoType
0
 

Author Comment

by:suelizy
ID: 36952161
Chrismerritt:  let me clarify what i meant by separate.  :)  

Ideally, i would like to run 1 command that would dump the data into 1 file.

second best:  run 1 command that puts the data in 2 files (1 for Get-MailboxFolderStatistics and 1 for Get-LogonStatistics.)

I already have 2 separate commands that give me 2 separate output files.

Thanks!


0
 
LVL 9

Accepted Solution

by:
chrismerritt earned 2000 total points
ID: 36952191
I see!

First one, not really possible I think as the data doesn't really sit well together, second one, try this.

Change the path and the usernames as you want:

$User = "Enter Username Here"
$ExportFileStats = "C:\Some Folder\SomeFile1.csv"
$ExportFileLogon = "C:\Some Folder\SomeFile2.csv"

get-mailbox $User | Get-MailboxFolderStatistics | select-object Identity,Folderpath,FolderType,itemsinfolder,@{Name="FolderSize KB";expression={$_.folderSize.toKB()}} | Export-CSV $ExportFileStats -NoType
Get-LogonStatistics $User | select windows2000account, databasename, clientversion, clientmode | Export-CSV $ExportFileLogon -NoType

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
In this video we show how to create a mailbox database 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 Servers >> Data…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Suggested Courses

809 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