Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Disk Space

$
0
0

Hello All

 

I write a code that give me all hard disks information but I would like to have in my report just the disks that are in Waning and Critical

please someone can help me

 

thanks

 

this is my code:

 

Function Check-DiskSpace

Param
    (
        [Parameter(Mandatory=$true)]
        [string[]]${ServerList}
    )

 

$sess = New-PSSession $ServerList;
    ${PercentFree} = Invoke-Command {Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq "3" } | Select-Object SystemName,VolumeName,DeviceID,@{ Name = "Size (GB)" ; Expression = { "{0:N1}" -f( $_.Size / 1gb) } },@{ Name = "Free Space (GB)" ; Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) } },@{ Name = "Percent Free" ; Expression = { "{0:P0}" -f( $_.FreeSpace / $_.Size ) } },    @{ Name = "WarningLevel" ; Expression = { $1 = (( $_.FreeSpace / $_.Size ) * 100); If ($1 -gt 35 ){"Good"} ElseIf ($1 -gt 15 ){"Warn"} Else {"Critical"}  }}   } -Session $sess;
    Remove-PSSession $sess;

    ${PercentFree} = ${PercentFree} | Select SystemName,VolumeName,DeviceID,"Size (GB)","Free Space (GB)","Percent Free","WarningLevel" | Sort-Object { [INT]($_."Percent Free" -replace '%')  } | ConvertTo-Html -Fragment -As Table -PreContent "<h2>Available Disk Space</h2>" | Out-String;
    ${PercentFree} = ${PercentFree} | Foreach-Object { $_ -replace "<td>Good</td>", "<td style=""background-color:Green; color:Black; Text-align:Center;"">Good</td>"};
    ${PercentFree} = ${PercentFree} | Foreach-Object { $_ -replace "<td>Warn</td>", "<td style=""background-color:Orange; color:Black; Text-align:Center;"">Warning</td>"};
    ${PercentFree} = ${PercentFree} | Foreach-Object { $_ -replace "<td>Critical</td>", "<td style=""background-color:Red; color:Black; Text-align:Center;"">Critical</td>"};
    return ${PercentFree};
}

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles