Welcome Forums General PowerShell Q&A Get-DbaDiskSpace returning blank values

Viewing 1 reply thread
  • Author
    Posts
    • #166471
      Participant
      Topics: 18
      Replies: 10
      Points: 102
      Rank: Participant

      I am using this cmdlet from dbatools to report on low disk space: Get-DbaDiskSpace

      Sometimes it returns blanks for certain drives like this:

      ComputerName Name Label Capacity Free PercentFree
      server1 D:\
      server2 E:\
      server3 G:\ sql_tempDB 99.89 GB 9.97 MB 0.01

      Here is my code:

      
      $allservers  = Get-DbaCmsRegServer -SqlInstance localhost -Group myCMSgroup
      
      $results = $allservers | Get-DbaDiskSpace | Where-Object PercentFree -lt 10
      
      if($results.count -gt 0) {
      $style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
      $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
      $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
      $style = $style + "TD{border: 1px solid black; padding: 5px; }"
      $style = $style + "</style>"
      
      $smtpServer = "smtprelay.us.myDomain.com"
      $smtpFrom = "noReply@myDomain.com"
      $smtpTo = "kevin.j.sexton@myDomain.com"
      $messageSubject = "Drives with less than 10% free space (PROD) (task:Drive Space Monitor-ks)"
      
      $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
      $message.Subject = $messageSubject
      #$message.Body = $allservers | Get-DbaDiskSpace | Where-Object PercentFree -lt 10  | select-object ComputerName,Name,Label,Capacity,Free,PercentFree | convertto-html -Head $style
      $message.Body = $results  | select-object ComputerName,Name,Label,Capacity,Free,PercentFree | convertto-html -Head $style
      
      $message.IsBodyHTML = $true
      
      $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
      $smtp.Send($message)
      } 
    • #166498
      Senior Moderator
      Topics: 8
      Replies: 1163
      Points: 4,070
      Helping Hand
      Rank: Community Hero

      Just to check free space, you don’t need to go for Get-DbaDiskSpace. Use Get-Volume cmdlet.

Viewing 1 reply thread
  • The topic ‘Get-DbaDiskSpace returning blank values’ is closed to new replies.