Get-DbaDiskSpace returning blank values

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

This topic contains 1 reply, has 2 voices, and was last updated by

 
Senior Moderator
2 months ago.

  • Author
    Posts
  • #166471

    Participant
    Topics: 17
    Replies: 10
    Points: 90
    Rank: Member

    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 = ""
    
    $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: 1041
    Points: 3,439
    Helping Hand
    Rank: Community Hero

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

You must be logged in to reply to this topic.