I need to show disks space free less than 99%.

Welcome Forums General PowerShell Q&A I need to show disks space free less than 99%.

Viewing 3 reply threads
  • Author
    Posts
    • #204696
      Participant
      Topics: 8
      Replies: 8
      Points: 93
      Rank: Member
      # Get SQL Server hostname
      $hostname=Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name
      
      # Get all drives with free space less than a threshold. Exclude System Volumes
      $Results = Get-WMIObject -ComputerName $hostname Win32_LogicalDisk |
      where{($_.DriveType -eq 3) -and ((($_.freespace/1gb)/($_.size/1gb)) -le '0.99')}
      
      ForEach ($Result In $Results)  # $Results variable does not contain values
      {
      $drive = $Result.DriveLetter # I can not set this variable
      $space = $Result.FreeSpace # I can not set this variable
      
      }
      • This topic was modified 3 months, 1 week ago by grokkit. Reason: please format your code as per the forum posting instructions
    • #204726
      Senior Moderator
      Topics: 3
      Replies: 123
      Points: 653
      Helping Hand
      Rank: Major Contributor

      Please share some more information about the specific problem you are experiencing, and what you have already done to try to resolve it.

    • #204807
      Participant
      Topics: 12
      Replies: 1622
      Points: 2,560
      Helping Hand
      Rank: Community Hero

      You should look specifically here:

      ((($_.freespace/1gb)/($_.size/1gb)) -le '0.99')
      

      ‘0.99’ is a string and is not converted to a number, so -le won’t work. Take a look at this post:

      outputs not working as expected

    • #205110
      Participant
      Topics: 8
      Replies: 8
      Points: 93
      Rank: Member

      solved

      I change code¬† ((($_.freespace/1gb)/($_.size/1gb)) -le ‘0.99’)

      now ((($_.freespace/1gb)/($_.size/1gb)) -le 0.99)

Viewing 3 reply threads
  • The topic ‘I need to show disks space free less than 99%.’ is closed to new replies.