Link to home
Start Free TrialLog in
Avatar of janhoedt
janhoedt

asked on

Powershell html report of usage C-drive

Hi,

I have an html report which shows CDrive usage of a server as red when over 80%, yello when between 70 and 80 and green
when other value.

It works fine except for some occasions, f.e. when 90% it shows green.

Hope example is clear. Please advise howto correct.

J.



#Get C-Drive percentage
		$volC = Get-WmiObject -Class win32_Volume -ComputerName $Computer -Filter "DriveLetter = 'C:'" | Select-Object -Property @{
        Name       = 'C PercentUsed'
        Expression = {
          '{0:N0}' -f  ((($_.Capacity - $_.FreeSpace ) / $_.Capacity)*100)
        }
      }
	  

#Get overviewtable	  
		$Result += [PSCustomObject] @{ 
		CDrive                = $volC.'C PercentUsed'
		...
		
		$CDriveAsPercent = "$($Entry.CDrive)%"
		
#Make the html
		Foreach ($entry in $Result)
		{
				  
		  # check C: Drive Usage
          if((($Entry.CDrive) -ge 80) -or (($Entry.CDrive) -eq 100))
          {
            $ComputerHealthOverviewFragment += "<TD bgcolor=red align=center>$($CDriveAsPercent)</TD>"
          }
          elseif((($Entry.CDrive) -ge 70) -and (($Entry.CDrive) -lt 80))
          {
            $ComputerHealthOverviewFragment += "<TD bgcolor=yello align=center>$($CDriveAsPercent)</TD>"
          }
          else
          {
            $ComputerHealthOverviewFragment += "<TD bgcolor=green align=center>$($CDriveAsPercent)</TD>"
          }
		  ...
		}
		

Open in new window

Avatar of Sunil Chauhan
Sunil Chauhan
Flag of India image

It doesn't require to put a bracket when the drive is greater than 80% so remove the same.

if((($Entry.CDrive) -ge 80) -or (($Entry.CDrive) -eq 100))

replace with

if (($Entry.CDrive) -ge 80)
Avatar of janhoedt
janhoedt

ASKER

Ok, but wil that solve my problem?
yes this should solve the problem.
Don't get that, if the value is gt 80 ... then the -or doesn't matter indeed but why would it be the root cause?
-or (($Entry.CDrive) -eq 100) this piece of code is unnecessary, other than that I do not see anything else to be problematic.
Ok, but I do not see it as problematic on itself.
ASKER CERTIFIED SOLUTION
Avatar of Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial