Category Archives: Uncategorised

Monitoring Office 365 Mailbox size

##############################################
#### Check Mailbox size Offce 365 ############
##############################################
$MailUser = $args[0]
$MailPWD = $args[1]
$SecureMailPWD = Convertto-SecureString –String $MailPWD –AsPlainText –force
$mailCred = New-object System.Management.Automation.PSCredential $MailUser, $SecureMailPWD
$To="your@email"
$From="server123"
$SMTPServer=$args[2]
#############################################
#### Login Details for Office 365 ###########
#############################################
$username = $args[3]
$pwd = $args[4]
$SecurePassword=Convertto-SecureString –String $pwd –AsPlainText –force
$MyCredentials=New-object System.Management.Automation.PSCredential $username,$SecurePassword
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $MyCredentials -Authentication Basic -AllowRedirection
#############################################

Import-PSSession $Session -DisableNameChecking | Out-Null

$query = (Get-Mailbox -ResultSize Unlimited | where {$_.Name -inotmatch "DiscoverySearchMailbox"} |Get-MailboxStatistics -WarningAction SilentlyContinue)

$formated = $query | Select DisplayName, @{name="TotalItemSize"; expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}, ItemCount

### Specifying the thresholds ###############

$warn = ($formated | Where-Object {$_.TotalItemSize -gt 45000})
$crit = ($formated | Where-Object {$_.TotalItemSize -gt 49000})

if ($warn){
Send-MailMessage -to $To -From $From -Subject "1^Server^Service^$warn" -SmtpServer $SMTPServer -Port 587 -Credential $mailCred
exit 1
}
elseif ($crit) {
Send-MailMessage -to $To -From $From -Subject "2^Server^Service^$crit" -SmtpServer $SMTPServer -Port 587 -Credential $mailCred
exit 2
}
elseif ($query = $null) {
Send-MailMessage -to $To -From $From -Subject "3^Server^Service^Status: UNKNOWN" -SmtpServer $SMTPServer -Port 587 -Credential $mailCred
exit 3
}
else {
Send-MailMessage -to $To -From $From -Subject "0^Server^Service^All mailboxes are bellow the tresholds" -SmtpServer $SMTPServer -Port 587 -Credential $mailCred
exit 0
}

Remove-PSSession $Session

Check for Veeam Endpoint Backup

##################################################################################################
##### Icinga check for Veeam Enedpoint Backup. It does check of the last backup date. #####
##### Accepted arguments are: BackupJobName and period of days for backup e.g a > b = fail:) #####
##################################################################################################

asnp VeeamPSSnapin

$name = $args[0]
$period = $args[1]

$job = Get-VBRBackup -Name $name
$name = "'" + $name + "'"

$status = $job.LastPointCreationTime.Split()[0]
$date =(Get-Date -Format d)

$check_period=((Get-Date).AddDays(-$period).ToString('dd/MM/yyyy'))

if ($job -eq $null)
{
Write-Host "UNKNOWN! No such a job: $name."
exit 3
}

if ( $status -gt $check_period ){
Write-Host "Backp hasn't been run since" $status
exit 1
}
if ($status -lt $date){
Write-Host "Backup Successful for $name"
exit 0
}