try { # Import admin credentials $serverAddress = Get-Content -Path ".\DefaultServer.txt" $credential = Import-Clixml -Path ".\AdminCredential.xml" # Establish session with Exchange Server $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$serverAddress/PowerShell/ -Authentication Kerberos -Credential $credential Import-PSSession $session -DisableNameChecking # Parameters from batch script $identity = $args[0] $size = $args[1] # Validate and process size input if ($size -match '^\d+GB$') { $sizeGB = [int]($size -replace 'GB$', '') $sizeBytes = $sizeGB * 1GB Write-Host "Debug: Setting mailbox quotas based on user input of $sizeGB GB..." -ForegroundColor Cyan } else { Write-Host "Invalid size input. Ensure size is in 'GB' format (e.g., '10GB')." -ForegroundColor Red return } # Adjust quotas based on user input $prohibitSendReceiveQuota = 4.5 * 1GB # Fixed at exactly 4.50GB (4.5 * 1GB) $prohibitSendQuota = 4.0 * 1GB # Fixed at exactly 4.00GB (4.0 * 1GB) $issueWarningQuota = 3.5 * 1GB # Fixed at exactly 3.50GB (3.5 * 1GB) # Debug quota values Write-Host "Debug: Issue Warning Quota: $([math]::Round($issueWarningQuota / 1GB, 2)) GB" -ForegroundColor Cyan Write-Host "Debug: Prohibit Send Quota: $([math]::Round($prohibitSendQuota / 1GB, 2)) GB" -ForegroundColor Cyan Write-Host "Debug: Prohibit Send and Receive Quota: $([math]::Round($prohibitSendReceiveQuota / 1GB, 2)) GB" -ForegroundColor Cyan # Step 1: Update UseDatabaseQuotaDefaults to false Write-Host "Updating UseDatabaseQuotaDefaults to false for $identity..." -ForegroundColor Yellow Set-Mailbox -Identity $identity -UseDatabaseQuotaDefaults $false # Step 2: Apply mailbox quotas Write-Host "Applying mailbox quotas for $identity..." -ForegroundColor Yellow Set-Mailbox -Identity $identity ` -IssueWarningQuota $issueWarningQuota ` -ProhibitSendQuota $prohibitSendQuota ` -ProhibitSendReceiveQuota $prohibitSendReceiveQuota Write-Host "Mailbox quotas successfully updated for $identity!" -ForegroundColor Green Write-Host "Issue Warning at: $([math]::Round($issueWarningQuota / 1GB, 2)) GB" Write-Host "Prohibit Send at: $([math]::Round($prohibitSendQuota / 1GB, 2)) GB" Write-Host "Prohibit Send and Receive at: $([math]::Round($prohibitSendReceiveQuota / 1GB, 2)) GB" # Remove session Remove-PSSession $session } catch { Write-Host "Failed to update mailbox quotas. Error:" -ForegroundColor Red Write-Host $_.Exception.Message }