Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created June 8, 2020 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/20ef6c448e9040d3e693d42de2402489 to your computer and use it in GitHub Desktop.
Save gitfvb/20ef6c448e9040d3e693d42de2402489 to your computer and use it in GitHub Desktop.
Quick example to check the amount of backups and the current used and free space on all local drives and send that information via smtp
$logfile = "D:\Apteco\Log\backup_manual.log"
# log
"$( [datetime]::Now.ToString("yyyyMMddHHmmss") )`t-------------------------------" >> $logfile
# Get all local drives that are currently used (used space greater than 0) and format the numbers and output as list
$currentSpace = Get-PSDrive -PSProvider FileSystem | where { $_.Used -gt 0 } | Select Root, @{name="Used (GB)";expression={ ($_.Used/1GB).ToString(".00") }}, @{name="Free (GB)";expression={ ($_.Free/1GB).ToString(".00") }} | fl
# check how many backups are in a folder
$backupFolder = "D:\Apteco\Publish\<sysname>\backup\"
$backupFolderCount = ( Get-ChildItem -Path $backupFolder ).count
# Create smtp mailing settings
$mailSettings = @{
smtpServer = "<smtpserver>"
from = "<fromaddress>"
to = "<toaddress>"
port = 25
}
Send-MailMessage -SmtpServer $mailSettings.smtpServer `
-From $mailSettings.from `
-To $mailSettings.to `
-Body "There are $( ( Get-ChildItem -Path $backupFolder ).count ) backups on $( $backupFolder )`n`nThis is the current space: `n$( $currentSpace | Out-String )" `
-Subject "There are $( ( Get-ChildItem -Path "E:\Apteco\Publish\buenting\backup\" ).count ) backups on E:\" `
-Port $mailSettings.port
"$( [datetime]::Now.ToString("yyyyMMddHHmmss") )`tSend Email to $( $mailSettings.to ) with the information of $( $backupFolderCount ) backups and space`n$( $currentSpace | Out-String ) " >> $logfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment