Exchange

Powershell Script to get mailbox size in MB for list of users in a CSV file with only Samaccountname
KAKA JIAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

timgreen7077Exchange EngineerCommented:
You can run the following:

$userlist = Import-Csv C:\temp\sizes.csv
foreach ($user in $userlist){
Get-MailboxStatistics -Identity $user.samaccountname | select displayname, totalitemsize | Export-Csv c:\temp\results.csv
}

In your csv file name the column 'samaccountname'
0
KAKA JIAuthor Commented:
Thanks TimGreen7077

I need further help

I am getting this error

in : Unexpected token 'in' in expression or statement.
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
KAKA JIAuthor Commented:
[PS] C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Exchange Server 2010>$userlist = Import-Csv "C:\spam\user.csv" foreach($user in $userlist){ Get-MailboxStatistics -Identity $user.SAMAccountName | select displayname, totalitemsize | Export-Csv "c:\spam\results.csv" }
in : Unexpected token 'in' in expression or statement.
    + CategoryInfo          : ParserError: (in:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
0
Make Network Traffic Fast and Furious with SD-WAN

Software-defined WAN (SD-WAN) is a technology that determines the most effective way to route traffic to and from datacenter sites. Register for the webinar today to learn how your business can benefit from SD-WAN!

Jason CrawfordTransport NinjaCommented:
Did you copy the last sentence of Tim's script also?  That was instructional in nature and should not be run from the command line.  Here it is separated:

You can run the following:

$userlist = Import-Csv C:\temp\sizes.csv
foreach ($user in $userlist){
Get-MailboxStatistics -Identity $user.samaccountname | select displayname, totalitemsize | Export-Csv c:\temp\results.csv
}

Open in new window

In your csv file name the column 'samaccountname'
0
Todd NelsonSystems EngineerCommented:
Try this command instead.  It will output DisplayName and TotalItemSize (in MB) for each SamAccountName in the list.  The other will only provide output for the last listed SamAccountName in the list...

Import-Csv C:\Spam\User.csv | foreach { Get-MailboxStatistics -Identity $_.SamAccountName | Select-Object DisplayName,@{label="TotalItemSize (MB)";expression={$_.TotalItemSize.Value.ToMB()}} } | Export-Csv C:\Spam\Results.csv -NoType

Open in new window

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
timgreen7077Exchange EngineerCommented:
Thanks @Jason for clarifying that for the user.

@Kaka tell me the name of your csv file and the version of exchange your are using and I will add it to the script for you.
0
KAKA JIAuthor Commented:
Thanks Todd that worked just fine
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.