locked
Exchange PowerShell script to get mailbox properties of user from a CSV file RRS feed

  • Question

  • Hi Team,

    I've a CSV file with alias of numerous users and I want to get their mailbox sizes and other properties. These users are dispersed in various databases of same Exchange organization.

    Need a Powershell Script, Any help?


    Muhammad Nadeem Ahmed Sr System Support Engineer Premier Systems (Pvt) Ltd T. +9221-2429051 Ext-226 F. +9221-2428777 M. +92300-8262627 Web. www.premier.com.pk

    Friday, November 22, 2013 4:02 PM

Answers

  • You can use this and modify it to what you need. Output to a file (IE: Export-CSV "path to file"

    If you need more specifics let me know. This one is for one user at a time but can be used to read a CSV file.

    # Notifies the user a remote session needs to be started
    Write-Host "Get a users mailbox size" -fore yellow -back red;
    Write-Host "Please wait while a remote session started" -fore red -back yellow;

    # Import a remote session with exchange
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeservername/Powershell/ -Authentication Kerberos
    Import-PSSession $Session


    Do {
    # Prompts user for a name
    $name = Read-Host "Enter a username"

    # Get the mailbox statistics for that user
    Get-MailboxStatistics $name | fl totalitemsize, storagelimitstatus, totaldeleteditemsize | out-default

    # Give the user a choice to test another or EXIT
    $Output = Read-Host "Press Y to continue or ENTER to exit"
    }

    # Ends the program if the user does not press Y
    Until ($Output -ne "Y")


    HossFly, Exchange Administrator

    Friday, November 22, 2013 8:22 PM

All replies

  • You can use this and modify it to what you need. Output to a file (IE: Export-CSV "path to file"

    If you need more specifics let me know. This one is for one user at a time but can be used to read a CSV file.

    # Notifies the user a remote session needs to be started
    Write-Host "Get a users mailbox size" -fore yellow -back red;
    Write-Host "Please wait while a remote session started" -fore red -back yellow;

    # Import a remote session with exchange
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeservername/Powershell/ -Authentication Kerberos
    Import-PSSession $Session


    Do {
    # Prompts user for a name
    $name = Read-Host "Enter a username"

    # Get the mailbox statistics for that user
    Get-MailboxStatistics $name | fl totalitemsize, storagelimitstatus, totaldeleteditemsize | out-default

    # Give the user a choice to test another or EXIT
    $Output = Read-Host "Press Y to continue or ENTER to exit"
    }

    # Ends the program if the user does not press Y
    Until ($Output -ne "Y")


    HossFly, Exchange Administrator

    Friday, November 22, 2013 8:22 PM
  • Any updates?

    HossFly, Exchange Administrator

    Thursday, December 12, 2013 6:41 PM
  • Hi HossFly,

    Thanks a lot for this useful script, it worked OK for one user at a time as you mentioned.

    Can you provide something specific which reads from a CSV file and outputs with total size in GBs, database and servername, if possible.

    I m not into scripting at all and I really find very difficult to write scripts but I've started and also let me know some good resources for Pshell scripting for Windows, ActiveDirectory, Hyper-V and Exchange, especially.

    Thanks.


    Muhammad Nadeem Ahmed Sr System Support Engineer Premier Systems (Pvt) Ltd T. +9221-2429051 Ext-226 F. +9221-2428777 M. +92300-8262627 Web. www.premier.com.pk

    Saturday, December 14, 2013 5:51 PM
  • From your exchange box run this script.
    #Gets a list of names that you created

    $Names = Get-Content C:\Users\"name"\desktop\listofusers.csv

    ForEach ($User in $Names)

    {

    Get-Mailboxstatistics -Identity $user | fl displayname, totalitemsize, storagelimitstatus | Out-File "C:\users\name\desktop\statsofusers.csv"

    }

    You can use any path you would like. I usually run from my desktop so you have to run Import-Session as described above. 

    Any questions let me know.


    HossFly, Exchange Administrator

    Monday, December 16, 2013 2:04 PM