Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Connect-EXOnline {
- param (
- [string]$Credential
- )
- $credentials = Get-Credential -Credential $Credential
- Write-Output "Getting the Exchange Online cmdlets"
- $Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
- -ConfigurationName Microsoft.Exchange -Credential $credentials `
- -Authentication Basic -AllowRedirection
- Import-PSSession $Session
- }
- Function disconnect-EXOnline {
- $session = Get-PSSession
- foreach ($id in $session) {
- if ($id.ConfigurationName -eq 'Microsoft.Exchange') {
- Remove-PSSession $session
- }
- }
- }
- function get-MailboxSize {
- param (
- [string]$UserMailbox
- )
- $CheckConnection = Get-PSSession
- cls
- if($null -eq $CheckConnection){
- Connect-EXOnline
- cls
- } else {
- if ($CheckConnection.ConfigurationName -ne "Microsoft.Exchange"){
- Connect-EXOnline
- cls
- }
- }
- $totalItemSize = Get-MailboxStatistics $UserMailbox | Select-Object TotalItemSize
- $totalItemSize = ($totalItemSize.TotalItemSize.value).tostring()
- $totalItemSize = $totalItemSize.trimend(" bytes)")
- $totalItemSize = $totalItemSize.Split("(")
- [string]$totalItemSize = $totalItemSize[1].Trim()
- $totalItemSize = $totalItemSize.Replace(',', '')
- [uint64]$MailboxSize = $totalItemSize / 1MB
- Write-Host $UserMailbox
- Write-host "Mailbox Size (MB):"
- $TotalItemSize = $null
- return $MailboxSize
- }
- #UserMailbox is the Mailbox you want to find the size of.
- get-MailboxSize -UserMailbox '<Enter Email Address>'
Add Comment
Please, Sign In to add comment