The powershell script below will return information on drives and mountpoints regardless of whether they host database files.
It has some minor deficiencies but works OK.
Has a critical threshold [%], below which items are highlighted with a red background.
Set the value of variable $server
param(
[int]$MountPointsOnly = $false,
[int]$CriticalThreshold = 15
)
$ErrorActionPreference = "Stop"
Clear-Host
$server = 'ThisServer'
$serverExists = ping "$server" -ne 1
if($serverExists -like "*Ping request could not find host*"){
Write-host "***`n`tCould not connect to server: $server`n***" #-BackgroundColor White -ForegroundColor Red
}else{
try{
if($MountPointsOnly){
$v = gwmi -class "win32_volume" -namespace "root/cimv2" -ComputerName $server | Where-Object {$_.capacity -ne $null -and $_.DriveLetter -eq $null}
}else{
$v = gwmi -class "win32_volume" -namespace "root/cimv2" -ComputerName $server | Where-Object {$_.capacity -ne $null}
}
$OddLine = $true
$PadChar = '.'
if($v -eq $null){
Write-Host "No Mountpoints present on server: $server" `
}else{
Write-Host "Storage Space Report [in GB] - $server"
Write-Host "Drive Label".padright(40," ") -BackgroundColor DarkBlue `
"Free".padleft(5," ") `
"Total".padleft(7," ") `
"% Free ".padleft(12," ") `
-ForegroundColor White
foreach($d in $v | sort -Property caption){
if($OddLine){
$PadChar = ' '
$background = "Gray"
$OddLine = $false
} else {
$PadChar = ' '
$background = "White"
$OddLine = $true
}
if(($d.freespace /$d.Capacity*100) -lt $CriticalThreshold){
write-host (($d.DriveLetter + "").padright(4," ") + " " + $d.label).padright(40,$PadChar) ("{0:#,##0}" -f ($d.freespace/ 1GB)).padleft(5," ") " " `
("{0:#,##0}" -f ($d.capacity/ 1GB)).padleft(5," ") " " `
('{0:P2}' -f ($d.freespace /$d.Capacity)).padleft(10," ") -BackgroundColor Red -ForegroundColor Black
}else{
write-host (($d.DriveLetter + "").padright(4," ") + " " + $d.label).padright(40,$PadChar) ("{0:#,##0}" -f ($d.freespace/ 1GB)).padleft(5," ") " " `
("{0:#,##0}" -f ($d.capacity/ 1GB)).padleft(5," ") " " `
('{0:P2}' -f ($d.freespace /$d.Capacity)).padleft(10," ") -BackgroundColor $background -ForegroundColor Black
}
}
}
}catch{
Write-host "*** Could not connect to server: $server ***" -BackgroundColor White -ForegroundColor Red
}
}