none
get-mailbox powershell command

    Question

  • Hi,

    I am trying to to create a power shell script to display the information as per below, any help would be greatly appreciated. Also is it possible to have another column to show if user is disable in AD or not,

    regards,

    Hazey

    Get-Mailbox

    foreach

    $DisplayName

    =Select-Object DisplayName


    $PrimarySMTPAddress

    =Select-Object PrimarySMTPAddress

    $IssueWarningQuota

    =Select-Object IssueWarningQuota


    $ProhibitSendQuota

    =Select-Object ProhibitSendQuota


    $WhenCreated

    =Select-Object WhenCreated


    $lastlogontime

    =get-MailboxStatistics | Select-Object lastlogontime


    $ItemCount

    =get-MailboxStatistics | Select-Object ItemCount


    $TotalItemSize

    =get-MailboxStatistics | Select-Object TotalItemSize


    $AdGroups

    =(Get-QADUser).memberof | Get-QADGroup| select name



    Export-Csv

    -Path c\results.csv -NoTypeInformation -append


    • Edited by HazeyF Sunday, October 19, 2014 10:02 PM
    Sunday, October 19, 2014 10:01 PM

Answers

  • Save the complete Script as a GetMailboxInfo.Ps1 File. Open Exchange Management Shell as administrator and run this PS1 File. Reply back in case if the you see any errors while the script execution.

    $Global:Report = @()
    Function GetMailboxDetails($List)
    {
    Write-Host -ForeGroundColor YELLOW "Import Active Directory Module"
    Import-Module ActiveDirectory
    		foreach($Line in $List)
    		{
    			$GroupInfo = @()
    			$CurrentMailbox = $Line.Alias
    			$MailboxObj = "" | Select DisplayName,Alias,PrimarySMTPAddress,SAMACcountNAme,Database,IssueWarningQuota,ProhibitSendQuota,WhenCreated,ExchangeUserAccountControl,TotalItemSize,LastLoggedOnBy,MemberOf
    			$MailboxObj.Alias = (Get-Mailbox $CurrentMailbox).Alias
    			$MailboxObj.DisplayName = (Get-Mailbox $CurrentMailbox).DisplayName
    			$MailboxObj.PrimarySMTPAddress = (Get-Mailbox $CurrentMailbox).PrimarySMTPAddress
    			$MailboxObj.SAMACcountNAme = (Get-Mailbox $CurrentMailbox).SamAccountName
    			$MailboxObj.Database = (Get-Mailbox $CurrentMailbox).Database
    			$MailboxObj.IssueWarningQuota = (Get-Mailbox $CurrentMailbox).IssueWarningQuota
    			$MailboxObj.ProhibitSendQuota = (Get-Mailbox $CurrentMailbox).ProhibitSendQuota
    			$MailboxObj.WhenCreated = (Get-Mailbox $CurrentMailbox).WhenCreated
    			[String]$AccountControl = (Get-Mailbox $CurrentMailbox).ExchangeUserAccountControl
    			$MailboxObj.ExchangeUserAccountControl = "DISABLED ACCOUNT"
    			If($AccountControl -eq "None")
    				{
    					$MailboxObj.ExchangeUserAccountControl = "ACTIVE"
    				}
    			$MailboxObj.TotalItemSize = (Get-MailboxStatistics $CurrentMailbox).TotalItemSize
    			$MailboxObj.LastLoggedOnBy = (Get-MailboxStatistics $CurrentMailbox).LastLoggedOnBy
    			
    			$DLGroupMembership = (Get-ADUser $Line.SamAccountName).MemberOf
    			for($i = 0;$i -lt $DLGroupMembership.Count;$i++)
    				{
    					$GroupInfo += $DLGroupMembership[$i]
    					$GroupInfo += ","
    				}
    			$MailboxObj.MemberOf = $GroupInfo
    			$Global:Report += $MailboxObj	
    		}
    }
    
    
    #-----------------------#
    #			MAIN		#
    #-----------------------#
    "`n+++Gathering Mailbox Info..."
    $MailboxList = Get-Mailbox -ResultSize Unlimited | Select DisplayName,Alias,PrimarySMTPAddress,SAMACcountNAme,Database,IssueWarningQuota,ProhibitSendQuota,WhenCreated,ExchangeUserAccountControl
    
    GetMailboxDetails $MailboxList
    Write-Host -ForeGroundColor GREEN "Exporting Report to CSV File..."
    $Global:Report | Export-Csv MailboxInfo.Csv -NoTypeInformation

    • Edited by PK M Monday, October 20, 2014 12:27 PM
    • Proposed as answer by PK M Monday, October 20, 2014 1:02 PM
    • Marked as answer by Amy.WangModerator Tuesday, October 28, 2014 7:51 AM
    Monday, October 20, 2014 12:15 PM

All replies

  • Hi

    Are you running this from the Exchange server or AD server? If so you will need to import the snap-ins from which ever server you are on, ie, if you on AD then Exchange etc.

    Secondly, when you run this does it give you any errors?


    Hope this helps. Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Monday, October 20, 2014 4:49 AM
    Owner
  • Save the complete Script as a GetMailboxInfo.Ps1 File. Open Exchange Management Shell as administrator and run this PS1 File. Reply back in case if the you see any errors while the script execution.

    $Global:Report = @()
    Function GetMailboxDetails($List)
    {
    Write-Host -ForeGroundColor YELLOW "Import Active Directory Module"
    Import-Module ActiveDirectory
    		foreach($Line in $List)
    		{
    			$GroupInfo = @()
    			$CurrentMailbox = $Line.Alias
    			$MailboxObj = "" | Select DisplayName,Alias,PrimarySMTPAddress,SAMACcountNAme,Database,IssueWarningQuota,ProhibitSendQuota,WhenCreated,ExchangeUserAccountControl,TotalItemSize,LastLoggedOnBy,MemberOf
    			$MailboxObj.Alias = (Get-Mailbox $CurrentMailbox).Alias
    			$MailboxObj.DisplayName = (Get-Mailbox $CurrentMailbox).DisplayName
    			$MailboxObj.PrimarySMTPAddress = (Get-Mailbox $CurrentMailbox).PrimarySMTPAddress
    			$MailboxObj.SAMACcountNAme = (Get-Mailbox $CurrentMailbox).SamAccountName
    			$MailboxObj.Database = (Get-Mailbox $CurrentMailbox).Database
    			$MailboxObj.IssueWarningQuota = (Get-Mailbox $CurrentMailbox).IssueWarningQuota
    			$MailboxObj.ProhibitSendQuota = (Get-Mailbox $CurrentMailbox).ProhibitSendQuota
    			$MailboxObj.WhenCreated = (Get-Mailbox $CurrentMailbox).WhenCreated
    			[String]$AccountControl = (Get-Mailbox $CurrentMailbox).ExchangeUserAccountControl
    			$MailboxObj.ExchangeUserAccountControl = "DISABLED ACCOUNT"
    			If($AccountControl -eq "None")
    				{
    					$MailboxObj.ExchangeUserAccountControl = "ACTIVE"
    				}
    			$MailboxObj.TotalItemSize = (Get-MailboxStatistics $CurrentMailbox).TotalItemSize
    			$MailboxObj.LastLoggedOnBy = (Get-MailboxStatistics $CurrentMailbox).LastLoggedOnBy
    			
    			$DLGroupMembership = (Get-ADUser $Line.SamAccountName).MemberOf
    			for($i = 0;$i -lt $DLGroupMembership.Count;$i++)
    				{
    					$GroupInfo += $DLGroupMembership[$i]
    					$GroupInfo += ","
    				}
    			$MailboxObj.MemberOf = $GroupInfo
    			$Global:Report += $MailboxObj	
    		}
    }
    
    
    #-----------------------#
    #			MAIN		#
    #-----------------------#
    "`n+++Gathering Mailbox Info..."
    $MailboxList = Get-Mailbox -ResultSize Unlimited | Select DisplayName,Alias,PrimarySMTPAddress,SAMACcountNAme,Database,IssueWarningQuota,ProhibitSendQuota,WhenCreated,ExchangeUserAccountControl
    
    GetMailboxDetails $MailboxList
    Write-Host -ForeGroundColor GREEN "Exporting Report to CSV File..."
    $Global:Report | Export-Csv MailboxInfo.Csv -NoTypeInformation

    • Edited by PK M Monday, October 20, 2014 12:27 PM
    • Proposed as answer by PK M Monday, October 20, 2014 1:02 PM
    • Marked as answer by Amy.WangModerator Tuesday, October 28, 2014 7:51 AM
    Monday, October 20, 2014 12:15 PM
  • Your script is excellent, Thank you. Is there a way to also have it give you Item count and Total Deleted item size? Thanks again.
    Friday, June 15, 2018 1:52 PM