PowerShell FOR DBA Part-4 (Monitor Disk Space and send Alerts)

Watch Part-1, Part-2, Part-3

 

 

Scripts

  • Get-DbaDiskSpace -ComputerName Sauras-Lenovo
  • Get-DbaDiskSpace -ComputerName Sauras-Lenovo|Where-Object {$_.Free/1gb -lt 120}|Select *
  • Get-DbaDiskSpace -ComputerName Sauras-Lenovo|Where-Object {$_.Free/1gb -lt 120}|Select *|Format-Table
  • Get-DbaDiskSpace -ComputerName Sauras-Lenovo|Where-Object {$_.Free/1gb -lt 120}|Select Name,Label,Capacity,Free,PercentFree,BlockSize|Format-Table|Out-File C:\Files\DiskSpace2.txt
  • $Email="YourUserName@gmail.com"
  • $Smtp="smtp.gmail.com"
  • $To="Recipient List"
  • $Subject="Alert-Disk Space"
  • $Body="Please Find Attached"
  • $Cred=(Get-Credential -Credential "$Email")
  • Send-MailMessage -To $To -From $Email -Subject $Subject -Body $Body -Attachments C:\Files\DiskSpace.txt -SmtpServer $Smtp -Credential $Cred -UseSsl -Port 587 -DeliveryNotificationOption Never

Follow me:

Blog: http://Sqldepository.com

YouTube : Sql depository

Facebook: https://www.facebook.com/sqldepository/

Google+ :https://plus.google.com/u/0/107093915534620159617

Author: Sauras Pandey

Sauras Pandey is an MCP, SQL Server DBA/Architect with 9+ years of experience working in a variety of environments

3 thoughts on “PowerShell FOR DBA Part-4 (Monitor Disk Space and send Alerts)

  1. Hi Sauras,

    I’m trying to run your command on my Windows Server 2012R2 Standard but unable to run first command “Get-DbaDiskSpace -ComputerName *******” and I’m getting below error.
    “The term ‘Get-DbaDiskSpace’ is not recognized as the name of a cmdlet, function, script file, or operable program.”

    Can you please help me to run all Get-DBA commands which you are able to run in your machine as shown in the video.

    And also, could you please help me in configuring email alert for my SQL Windows Servers like whenever any of the disk space(C or D or E or F) goes below 10% it should shoot an email automatically.

    Regards,
    SQL Support

    1. is dbatools module installed on your machine where your are the command?

      check for dbatools folder in C:\Program Files\WindowsPowerShell\Modules

      if not, execute “Install-module dbatools” in powershell to install dbatools module.

      Thanks,
      Sauras

Leave a Reply

Your email address will not be published.