Hi experts i am using the below ps1 to get mailbox statistics from exchange online powershell module for 3500 users, but i am getting session timeout on powershell so i have exported my mailboxes to a csv file, i want to import the csv file and pull the below information, experts guide me on this.

foreach($users in Get-Mailbox -ResultSize Unlimited){$users | Foreach-Object {   
$user = $_ 
$stats = Get-MailboxStatistics $user.Name       
New-Object -TypeName PSObject -Property @{       
FirstName = $User.Firstname
LastName = $User.Lastname
IssueWarningQuota = $User.IssueWarningQuota       
ProhibitSendQuota = $User.ProhibitSendQuota       
ProhibitSendReceiveQuota = $User.ProhibitSendReceiveQuota     
TotalItemSize = $stats.TotalItemSize               
} 
}
}

4 Spice ups

If you post code, please use the insert code button! Please and thank you!

codebutton_small.png

try this

$outtbl = @()
$users = Get-Mailbox -ResultSize Unlimited
$users | % {
  $x = Get-MailboxStatistics $_ | Select TotalItemSize
  $t = New-Object PSObject -Property @{
Name = $_.Name
FirstName = $_.Firstname
LastName = $_.Lastname
IssueWarningQuota = $_.IssueWarningQuota       
ProhibitSendQuota = $_.ProhibitSendQuota       
ProhibitSendReceiveQuota = $_.ProhibitSendReceiveQuota     
TotalItemSize = $X.TotalItemSize
  }
  $outtbl += $t
}

$outtbl ## to export | Sort TotalItemSize -Descending | Export-Csv c:\ussersxx.csv -nti

I have exported mailboxes using the below syntax

Get-Mailbox -ResultSize unlimited | select userprincipalname >> C:\myusers.csv.

using my users.csv i want to get the below information

FirstName
LastName
Display Name
userprincipalname
IssueWarningQuota
ProhibitSendQuota
ProhibitSendReceiveQuota
TotalItemSize

The reason why i want get the mailbox statistics using myusers.csv is because of time interval set on exchangeonline Powershell module, to export 3500 users info will take lot of time and my session will get disconnected

1st name lastname do do support here, maybe this helps

$outtbl = @()
$users = Get-Mailbox -ResultSize Unlimited|select alias, Name,displayname,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,@{n='Firstname';e={$_.displayname.split(' ')[0]}},@{n='Lastname';e={$_.displayname.split(' ')[1]}}
$users | % {
  $x = Get-MailboxStatistics $_.alias | Select TotalItemSize
  $t = New-Object PSObject -Property @{
Name              = $_.Name
Firstname         = $_.Firstname
LastName          = $_.lastname
IssueWarningQuota = $_.IssueWarningQuota       
ProhibitSendQuota = $_.ProhibitSendQuota       
ProhibitSendReceiveQuota = $_.ProhibitSendReceiveQuota     
TotalItemSize    = $X.TotalItemSize
  }
  $outtbl += $t
}

$outtbl ## |export-csv c:\data.csv -NoTypeInformation
1 Spice up

I verified the script @JitenSh provided in my Office365 lab, it works as expected.

@jitensh

The problem for me is that after 15 minutes exchangeonline powershell gets disconnected because of timelimit set on it. so i want to import few users from csv file and run the script i am trying the below ps1 for which i am getting error

i have csv file by name myusers.csv where i have the below information

Users
user1@mydomain.com
user2@mydomain.com
user3@mydomain.com

i am trying to run the below ps1 for which i am getting error

.\mailboxstat.ps1 -ResultSize unlimited | Export-Csv “C:\output.csv” -notypeinformation

$users=import-csv C:\myusers.csv
foreach($user in $users){
$users | Foreach-Object {
$user = $_ 
$stats = Get-MailboxStatistics $user.userprincipalname
$a=get-user $user.userprincipalname      
New-Object -TypeName PSObject -Property @{      
FirstName = $a.Firstname
LastName = $a.Lastname
DisplayName = $User.DisplayName
IssueWarningQuota = $user.IssueWarningQuota      
ProhibitSendQuota = $user.ProhibitSendQuota      
ProhibitSendReceiveQuota = $user.ProhibitSendReceiveQuota    
TotalItemSize = $stats.TotalItemSize              
} 
}
}

Cannot bind argument to parameter ‘Identity’ because it is null.

  • CategoryInfo : InvalidData: (:slight_smile: [Get-MailboxStatistics], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxStatistics
  • PSComputerName : outlook.office365.com

your question and point you are trying to make is irrelevant you did not say you have csv and 15 Disconnect session is out of the scope of this post, it will disconnect you don’t need to keep it idle for 15 minutes just to export users.

You need to run it as and remove header in csv just put userprincipal names

$users=get-content C:\myusers.csv
foreach($user in $users){
$stats = Get-MailboxStatistics $user
$a=get-mailbox $user
New-Object -TypeName PSObject -Property @{      
FirstName = $a.Firstname
LastName = $a.Lastname
DisplayName = $a.DisplayName
IssueWarningQuota = $a.IssueWarningQuota      
ProhibitSendQuota = $a.ProhibitSendQuota      
ProhibitSendReceiveQuota = $a.ProhibitSendReceiveQuota    
TotalItemSize = $stats.TotalItemSize              
} 
}