Exchange Powershell
I have a list of user in CSV format. My cmdlet is to import the csv file then check which mailbox is with StorageStatusLimit = MailboxDisabled. If yes then increase mailbox. The cmdlet is working but, it appear that it also try to increase mailbox
size for ok mailbox. The cmdlet is:
$mbx = Import-Csv C:\Users\scpsupport\Documents\Migrate31052011.csv
foreach ($mbxs in $mbx){
$1 = Get-MailboxStatistics -Identity $mbxs.alias | where{ $_.StorageLimitStatus -eq 'MailboxDisabled'}
#$2 = $1.totalitemsize.value.toKB()
#$2
$3 = [Int]$1.totalitemsize.value.toKB()+(50*1024) #-ErrorAction SilentlyContinue
$4 = [String]$3+'KB'
#$2=$1.totalitemsize
#$3 = $2.value.toKB()
#$mbxs = [String]$mbxs+'KB'
Set-Mailbox -Identity $mbxs.alias -IssueWarningQuota $4 -ProhibitSendQuota $4 -ProhibitSendReceiveQuota $4 `
-UseDatabaseRetentionDefaults:$false -WhatIf
When I run this cmdlet. There is error like below appear:
You cannot call a method on a null-valued expression.
At line:8 char:38
+ $3 = [Int]$1.totalitemsize.value.toKB <<<< ()+(50*1024) #-ErrorAction SilentlyCo
ntinue
+ CategoryInfo : InvalidOperation: (toKB:String) [], RuntimeExceptio
n
+ FullyQualifiedErrorId : InvokeMethodOnNull
June 2nd, 2011 12:07pm
Hi there,
you're missing an if-statement to make the distinction between mailboxes that do and do not cross the limit
$mbx = Import-Csv C:\Users\scpsupport\Documents\Migrate31052011.csv foreach ($mbxs in $mbx){ $a = Get-MailboxStatistics -Identity $mbxs.alias if($a.StorageLimitStatus -eq "MailboxDisabled"){ $3 = $a.totalitemsize.value.toKB()+(50*1024) Set-Mailbox -Identity $mbxs.alias -IssueWarningQuota $3 -ProhibitSendQuota $3 -ProhibitSendReceiveQuota $3 -UseDatabaseRetentionDefaults:$false }}
Edit: for clarity, I've completed the script to do what you've asked for. You certainly don't need to manually add the 'KB'.
Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2011 12:51pm
To share if we did use cmdlet: $3 = $a.totalitemsize.value.toKB()+(50*1024)
The final mailbox size will be 157KB (e.g if mailbox size limit is 102400KB). When we aset mailbox size, we need to inform EMS that which unit of mailbox size we try to use KB,MB and etc. Without this unit, the default value is bytes. Mean that we set mailbox
with following cmdlet
set-mailbox -identity admin -IssueWarningQuota 102400 -ProhibitSend 102400 , this same as set-mailbox -identity admin -IssueWarningQuota 102400B -ProhibitSend 102400B
So with help from MichaelVH,my final code is:
<pre lang="x-powershell">$mbx = Import-Csv C:\Users\scpsupport\Documents\Migrate06062011.csv
foreach ($mbxs in $mbx){
$mb = Get-MailboxStatistics -Identity $mbxs.alias
If ($mb.StorageLimitStatus -eq 'MailboxDisabled'){
$2= [int]$mb.totalitemsize.value.toKB()+(50*1024)
$3= [string]$2+'KB'
Set-Mailbox -Identity $mbxs.alias -IssueWarningQuota $3 -ProhibitSendQuota $3 -ProhibitSendReceiveQuota $3 -UseDatabaseQuotaDefaults:$false
}
}
June 6th, 2011 6:59pm