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?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

All Courses

From novice to tech pro — start learning today.