GWI Win32_Volume threshold not working

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Anand Maini Anand Maini 2 years, 3 months ago.

  • Author
    Posts
  • #18611
    Profile photo of Anand Maini
    Anand Maini
    Participant

    Hi All
    I am hoping to get some assistance as this script has been doing my head in.
    Taken snippets from multiple sources.

    Objective: Report back on servers where percentfree space is less than 10%. This is for drives such as CSV drives where the drive letter is not assisgned. I can get the report to give me the output however it is giving me the drives even above the threshold

    $TotalGB = @{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}}
    $FreeGB = @{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}}
    $FreePerc = @{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
    
    #grab the names of the servers/computers to check from the list.txt file.
    $computers = get-content "C:\temp\servers.txt"
    
    # Set free disk space threshold below in percent (default at 10%)
    [decimal]$thresholdspace = 10
    
    
    #assemble together all of the free disk space data from the list of servers and only include it if the percentage free is below the threshold we set above.
    
    $tableFragment= Get-WMIObject -Computer $computers Win32_Volume |
    
    Where-Object {$_.DriveLetter -eq $null -AND $_.label -ne "System Reserved" -AND $_.FreePerc -lt [decimal]$thresholdspace}  | select __SERVER, Label, $TotalGB, $FreeGB, $FreePerc
    
    $tableFragment
    
    

    Would really appreciate any assistance

  • #18612
    Profile photo of Anand Maini
    Anand Maini
    Participant

    And right after I post this I figured it out. Probably not the cleanest

    Where-Object {$_.DriveLetter -eq $null -AND $_.label -ne "System Reserved" -AND (((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0) -lt $thresholdspace}  | select __SERVER, Label, $TotalGB, $FreeGB, $FreePerc
    

You must be logged in to reply to this topic.