Powershell script to capture both Mailbox AND Home directory size

Hello.  I need to get the Exchange Mailbox size and network home folder size for each user in my company.  I know how to get the mailbox sizes but is there a way to create a powershell script that captures both pieces at the same time?  I would like the mailbox and the home directory sizes exported to a .csv file.   Ideally though I would like to be able to send each user an email which contains their own mailbox and home directory size information.  Can this be done?  If so, how?

Thanks!
wrc2810Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
This can definitely be done with scripting. But have you looked into use FSRM? That might be a better way of alerting users.

https://technet.microsoft.com/en-us/library/cc732431.aspx

If you want to do it with a script, something like this can get you started. You should be able to add this to your exchange script.
Import-Module activedirectory
$homeDir = (Get-ADUser user -PropertiesHomeDirectory).HomeDirectory 
$homedirSize = Get-ChildItem $homeDir | Measure-Object -Property length -Sum

Open in new window

Instead of "user" you can use a variable to loop through your users and get the info.

You can then use Send-MailMessage to send out the info to the various users.

If you want to post your script then we can work on specifics for your environment.
0
wrc2810Author Commented:
Great.  This is the powershell script I currently use to get the mailbox information:

Get-MailboxStatistics  -Database “DB01” | Select DisplayName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime | Sort-Object TotalItemSize -Descending | Export-CSV c:\mailboxsize.csv

How do I add this script to the one you suggested?  Do I just run this in the Exchange Powershell?  Sorry, I have limited experience with powershell.

Thanks!
0
Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Perhaps something like this then.
Edit the first 3 variables for your environment. You'll also need to configure a receive connector to allow the server you're running this one to relay or you'll need to specify credentials for the send-mailmessage command. Please tweak the message to reflect what you want it to say as well. I would also have it send to your email for testing before you use the variable for the user's email.
$fromemail = 'admin@company.com'
$emailsubject = 'Home Directory and Mailbox size'
$EmailServer = 'exchangeSrv.domain.local'


$MBXs = Get-Mailbox -Database "DB01"

Foreach($mbx in $mbxs){
    $homeDir = (Get-ADUser Get-ADUser $(($mbx.UserPrincipalName).split('@')[0]) -Properties HomeDirectory).HomeDirectory 
    $homedirSize = ((Get-ChildItem $homeDir | Measure-Object -Property length -Sum).Sum /1mb).ToSting("f0")
    $Properties = Get-MailboxStatistics  $mbx | Select DisplayName, LastLoggedOnUserAccount, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime, @{name="HomeDirSize";Expression={$homedirSize}}
    $message = @"
Greetings $($Properties.Displayname),

    Your home directory size is $($Properties.HomeDirSize) MB.
    Your mailbox size is $($Properties.TotalItemSize.ToString()).
    Total number items in your mailbox is $($Properties.ItemCount).

Regards,
IT Department
"@

    
    Send-MailMessage -Body $message -From $fromemail -Subject $emailsubject -To $mbx.WindowsEmailAddress -SmtpServer $EmailServer 
    }

Open in new window

Let me know if you have any questions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wrc2810Author Commented:
Thank You!
0
wrc2810Author Commented:
I thought I had this working but no such luck.  Specifically what variables do i need to change?  Also, do I just copy and paste this into Exchange Powershell?

Thanks,
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

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.