We help IT Professionals succeed at work.
Get Started

Powershell html report of usage C-drive

janhoedt
janhoedt asked
on
208 Views
Last Modified: 2017-11-23
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

Comment
Watch Question
Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE